How to delete the listbox item in wp7? - windows-phone-7

Listbox having 2 buttons.When click on button need to delete the item from that listbox.
please tell me how to acheive that?
List<SampleCheckedData> interestrates = new List<SampleCheckedData>();
interestrates = (from rts in xmlDocu.Descendants("Friend")
select new SampleCheckedData
{
Id = (string)rts.Element("userid"),
Name = (string)rts.Element("name"),
Icon = (string)rts.Element("imageurl"),
VisibleStatus = (string)rts.Element("visiblestatus"),
AppStatus = (string)rts.Element("loginstatus"),
imgBubble =bitmapRed,
}).ToList<SampleCheckedData>();
this.lstImages.ItemsSource = interestrates;
private void btnAccept_MouseEnter(object sender, MouseEventArgs e)
{
int _id = int.Parse(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag.ToString());
lstFriendRequuest.Items.RemoveAt(lstFriendRequuest.SelectedIndex);
}

To delete the selected item,
listbox.Items.RemoveAt(listbox.SelectedIndex);

Make your collection available globally on this page, and now you can manipulate on it easily from btnAccept_MouseEnter event:
public interestrates;
...
{
interestrates = ...
this.lstImages.ItemsSource = interestrates;
}
private void btnAccept_MouseEnter(object sender, MouseEventArgs e)
{
interestrates.RemoveAt(lstFriendRequuest.SelectedIndex);
}
Also, make sure that a click on a ListBox item changes SelectedIndex accordingly

Related

ActiveExplorer().Selection returns previously selected mail in Outlook C#

I've following code. When user clicks on Reply or Reply button, it will pass the original email which will be process on SendAndComplete button.
public partial class ThisAddIn
{
public object selectedObject = null;
Outlook.MailItem mailItem = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Application application = this.Application;
Outlook.Explorer currentExplorer = application.ActiveExplorer();
//Get this event fire when selection changes
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
public void CurrentExplorer_Event()
{
if (this.Application.ActiveExplorer().Selection.Count == 1
&& this.Application.ActiveExplorer().Selection[1] is Outlook.MailItem)
{
selectedObject = this.Application.ActiveExplorer().Selection[1];
mailItem = selectedObject as Outlook.MailItem;
((Outlook.ItemEvents_10_Event)mailItem).Reply += new Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
((Outlook.ItemEvents_10_Event)mailItem).ReplyAll += new Outlook.ItemEvents_10_ReplyAllEventHandler(MailItem_ReplyAll);
}
}
void MailItem_Reply(object response, ref bool cancel)
{
//No code here
}
void MailItem_ReplyAll(object response, ref bool cancel)
{
//No code here
}
}
Now the selectedObject will be used on Ribbon.cs on button click.
public void SendnCompleteButton_Click(Office.IRibbonControl control)
{
Outlook.Application application = new Outlook.Application();
var addIn = Globals.ThisAddIn;
Outlook.MailItem mailItem = addIn.selectedObject as Outlook.MailItem;
MessageBox.Show(mailItem.Subject + " " + mailItem.ReceivedTime + " " + mailItem.Sender.Name)
}
Message box is showing previously selected email, how do I release the previously selected object?
Thank you.
First of all, there is no need to create a new Outlook Application instance in the ribbon button's event handler:
Outlook.Application application = new Outlook.Application();
Instead, you need to use the Globals.ThisAddIn.Application property or just the add-in class which provides the Application property out of the box.
Second, you must declare the event source object at the global scope, for example:
Outlook.Explorer currentExplorer;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
currentExplorer = Application.ActiveExplorer();
//Get this event fire when selection changes
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
Third, checking whether a single item is selected in Outlook UI is not correct. Instead, you should check whether any item is selected:
if (this.Application.ActiveExplorer().Selection.Count > 0)

Telerik Radgrid Access Values

I want to access values of the insert form in Telerik radgrid. how can i do that this is what i am trying
protected void RadGrid3_InsertCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string a = (editedItem.FindControl("ID") as TextBox).Text;
string b = (editedItem.FindControl("Quantity") as TextBox).Text;
}
}
It throws me the following error
Object reference not set to an instance of an object.
When editing or inserting a grid item, you could access and modify the controls generated in the editable item (reference Telerik documentation).
Try something like this:
protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editableItem = e.Item as GridEditableItem;
string a= editableItem["Id"].Controls[0] as TextBox;
string b= editableItem["Quantity"].Controls[0] as TextBox;
}
}
Please note that I have not tested the the above snippet. For more references you can look here

How to get list item index when user clicks on the button which is in list item in windows phone 8

I've list box in my application.
Below is the screen shot.
When user clicks on the list item, then i'm displaying detailed page.
It is handling in below selection changed listener.
private void companiesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//get the selected item from list
Company selectedItem = (Company)e.AddedItems[0];
Uri uri = new Uri("/CompanyDetailsPage.xaml", UriKind.Relative);
//navigate to target page
this.NavigationService.Navigate(uri);
FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
root.DataContext = selectedItem;
}
}
Upto this it is fine.
Now when the user clicks on the Delete button which is on the item,
then i've to delete that item from the list.
private void Del_Btn_clicked(object sender, RoutedEventArgs e)
{
//get the Corresponding item from list i.e. On which delete button is placed.
//Delete saved company from the database
}
I'm unable to get that particular list item index on which the delete button is placed.
Ho could I get.
Thanks.
You can retrieve the button by casting the sender parameter. From there, you can retrieve the company by casting the DataContext property:
private void Del_Btn_clicked(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var company = (Company)button.DataContext;
// ...
}
do get the index of the listbox you can direct set the property
SelectedIndex = {Binding asd,Mode=TwoWay}
then in viewmodel
make a property
private int _asd;
public int asd
{
get
{
return _asd;
}
set
{
_asd= value;
}
}
by this you will get the index of selected item ...
hopes it might help ..

Unable to show the selected item in the Wp7 Listpicker control

Basically i am trying to pull the contacts from the phone and showing them in the Listpicker control for a feature in my app. I have two Listpickers, one for name of contacts list and the other showing the list of phonenumbers for the chosen contact.
Here is my code:
//Declarations
ContactsSearchEventArgs e1;
String SelectedName;
String SelectedNumber;
List<string> contacts = new List<string>();
List<string> phnum = new List<string>();
public AddressBook() // Constructor
{
InitializeComponent();
Contacts contacts = new Contacts();
contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
contacts.SearchAsync(string.Empty,FilterKind.None,null);
}
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
e1 = e;
foreach (var result in e.Results)
{
if (result.PhoneNumbers.Count() != 0)
{
contacts.Add(result.DisplayName.ToString());
}
}
Namelist.ItemsSource = contacts;
}
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum.Clear();
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
private void Numbers_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedNumber = (sender as ListPicker).SelectedItem.ToString();
}
Am able to populate the Numberlist with phonenumbers for the chosen name at the Listpicker background, but the number is not showing up in the front. I think Numbers_SelectionChanged() event is called only one time when the page loads and am not seeing it triggerd when i change the contact list. Anyone has an idea of where am going wrong ?
If you change
List<string>
To
ObservableCollection<string>
this should work.
Also then you only need to set the ItemSource once, in Xaml or you constructor.
But you may run into another issue with the November 2011 Toolkit and ListPicker.
See more in thread.
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum = new List<string>(); // Changed instead of phnum.Clear()
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
This works !!. While debugging i found its phnum.Clear() giving a problem. So i thought to create a new instance of phnum list for selected contact.

Cant get selected listboxitem to show on my detail page

I have made and rss reader and have a listbox with all the feeds in it. When I select one item and want to see the whole article I only get the selectedindex number, 0,1,2 and so on.
Here is my code:
private void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
NavigationService.Navigate(new Uri("/DetailsPage.xaml?feeditem=" + listBox.SelectedIndex, UriKind.Relative));
}
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string feeditem = "";
if (NavigationContext.QueryString.TryGetValue("feeditem", out feeditem))
{
this.textBlock1.Text = feeditem;
}
}
What am I missing here?

Resources