Capturing WPF Listbox checkbox selection
- by wonea
Been trying to figure out, how do I capture the events from a listbox. In the template, I've added the parameter IsChecked="" which starts my method. However, the problem is trying to capture what has been checked in the method. SelectedItem only returns what is currently selected, not the checkbox.
object selected = thelistbox.SelectedItem;
DataRow row = ((DataRowView)selected).Row;
string teststring = row.ItemArray[0].ToString(); // Doesn't return the checkbox!
<ListBox IsSynchronizedWithCurrentItem="True" Name="thelistbox" ItemsSource="{Binding mybinding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Content="{Binding personname}" Checked="CheckBox_Checked" Name="thecheckbox"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>