sidd2004k
sidd2004k

Reputation: 49

To get Selected the Checkbox value of listview in WPF

I am having the code like

<ListView ItemsSource="{Binding}"  Height="110.277" Margin="4,0,3,-138" Name="listView1" VerticalAlignment="Bottom">
   <ListBox.ItemTemplate>
      <DataTemplate>

        <!--<TextBlock Text="{Binding Path=Name}" Width="100" />-->
        <!--<CheckBox  IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"  Width="100"/>-->
        <CheckBox Name="chk1" Content="{Binding Path=Name}" IsChecked="{Binding IsPersonChecked}" Checked="checked_accname"   Width="100" />

      </DataTemplate>
 </ListBox.ItemTemplate>

In which I will bind the value for checkbox dynamically from db at buttonclick event I can't able to get the value of checked checkbox of listview.

Please help me regarding this. Thanks in Advance

Upvotes: 0

Views: 2042

Answers (1)

Emond
Emond

Reputation: 50712

Do not try to get the checked value from the UI. Use the IsPersonChecked property from the data object.

var persons = listView1.DataContext as Persons;
var selectedPersonsQuery = from person in persons
                           where person.IsPersonChecked
                           select person;

EDIT

After understanding that you used a DataView your query would be something like this:

var dataView = listView1.DataContext as DataView;
var selectedPersonRowsQuery = from row in dataView
                              where row["IsPersonChecked"]
                              select row;

Upvotes: 1

Related Questions