3

How do I get CheckBox.Checked item, my checkbox is inside listBox and listbox is binded with a class. My class has two items: Name and Id

My code below:

I want that when I check on checkbox, in the background, I want Id of checked item.

private void CheckBox1_Checked(object sender, RoutedEventArgs e)
{
    ListBoxItem checedItem = this.listBox1.ItemContainerGenerator.ContainerFromItem((sender as CheckBox).DataContext) as ListBoxItem;

    if (checedItem != null)
    {
        checedItem.IsSelected = true;
    }
}
Phoenix
  • 1,045
  • 1
  • 14
  • 22
Nitesh Kothari
  • 890
  • 12
  • 27
  • Can a user check more than one checkbox at a time? Where do you want to store the IDs? – Matthijs Jun 19 '14 at 06:35
  • @Matthijs At a time,only one checkBox,I want to store in string.thank you!!guide me. – Nitesh Kothari Jun 19 '14 at 06:40
  • Take a look here: http://social.msdn.microsoft.com/forums/wpapps/en-US/48ec43bc-121d-407a-acdc-d8b90396f673/how-to-access-checkboxes-inside-list-box-in-c-in-windows-phone-8 – Matthijs Jun 19 '14 at 07:17

1 Answers1

0

May this help you.

private void CheckBox1_Checked(object sender, RoutedEventArgs e)
{
    var checkBox = (CheckBox)sender;\
    var data = (Your class)checkBox.DataContext;
    var id = data.id;
}
Jaihind
  • 2,770
  • 1
  • 12
  • 19