Capturing WPF Listbox checkbox selection

Posted by wonea on Stack Overflow See other posts from Stack Overflow or by wonea
Published on 2010-05-14T16:19:41Z Indexed on 2010/05/14 16:24 UTC
Read the original article Hit count: 472

Filed under:
|
|

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>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#