在WPF中选中listview的复选框值
我有这样的代码在WPF中选中listview的复选框值,wpf,checkbox,selected,Wpf,Checkbox,Selected,我有这样的代码 <ListView ItemsSource="{Binding}" Height="110.277" Margin="4,0,3,-138" Name="listView1" VerticalAlignment="Bottom"> <ListBox.ItemTemplate> <DataTemplate> <!--<TextBlock Text="{Binding Path=Name}" Wid
<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>
在其中,我将在按钮单击事件时从db动态绑定复选框的值。我无法获取listview的复选框的值
请帮我解决这个问题。提前感谢不要尝试从UI获取选中的值。使用数据对象中的IsPersonChecked属性
var persons = listView1.DataContext as Persons;
var selectedPersonsQuery = from person in persons
where person.IsPersonChecked
select person;
编辑
理解使用DataView后,您的查询将如下所示:
var dataView = listView1.DataContext as DataView;
var selectedPersonRowsQuery = from row in dataView
where row["IsPersonChecked"]
select row;
有什么问题?如果您在listview1.DataContext中提到Persons(什么是Persons),那么您的代码应该可以正常工作。我在上查看错误Persons@karthik2004k-Persons是绑定到listbox的对象集合。嗨,我已在windowload事件中将checkbox的值动态绑定为DataSet dss=dal.get_user();listView1.ItemsSource=dss.Tables[0].DefaultView;那么,我如何在运行时在这种情况下获取复选框值呢scenarios@karthik2004k-我补充了我的答案。同样,不要试图获取复选框的状态,而是读取列的值。