C# 带组合框的WPF过滤器
我是WPF新手,我想用C# 带组合框的WPF过滤器,c#,wpf,combobox,filter,C#,Wpf,Combobox,Filter,我是WPF新手,我想用CollectionView和我的ComboBox控件过滤一些数据 到目前为止我所做的: 政务司司长: private int count=0; 无效筛选器(对象发送器、筛选器目标) { 如果(值==“”| |值==null) { e、 接受=正确; } 其他的 { System.Xml.xmlement ele=e.项为System.Xml.xmlement; string name=ele.SelectNodes(“/response/contacts/conta
CollectionView
和我的ComboBox
控件过滤一些数据
到目前为止我所做的:
政务司司长:
private int count=0;
无效筛选器(对象发送器、筛选器目标)
{
如果(值==“”| |值==null)
{
e、 接受=正确;
}
其他的
{
System.Xml.xmlement ele=e.项为System.Xml.xmlement;
string name=ele.SelectNodes(“/response/contacts/contact/contact\u grname”)[count].InnerText;
计数+=1;
//MessageBox.Show(名称);
如果(名称==“组1”)e.已接受=真;
否则e.接受=错误;
}
}
此代码成功过滤mycontact_grname
元素中包含group1
文本的所有元素
但是如何绑定到我的组合框
,其中包含所有联系人姓名
(XML绑定)
如果我理解正确,您希望将另一个组合框绑定到第一个组合框组中的项目
<XmlDataProvider x:Key="TeleData" XPath="/response/contacts/contact" Source="C:\Data.xml" />
<CollectionViewSource x:Key="TeleView" Source="{StaticResource TeleData}" >
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="contact_name" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="contact_grname" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
<StackPanel>
<ComboBox ItemsSource="{Binding Source={StaticResource TeleView}, Path=Groups}" DisplayMemberPath="Name" Name="comboGroups" />
<ComboBox ItemsSource="{Binding ElementName=comboGroups, Path=SelectedItem.Items}" DisplayMemberPath="contact_name" Name="comboNames" />
</StackPanel>
结果:
一旦在
组合框中选择了一个项目
,根据所选项目过滤要显示的元素,调用过滤器
方法,将在组合框中选择的值传递给它
然后,使用以下命令刷新datagrid:
yourDataGrid.Items.Refresh()代码>
以及具有以下功能的CollectionView:
yourCollectionView.Refresh();
此外,请阅读这篇文章,解释CollectionView
的功能。嘿,你想用另一个组合框中所选组的项目填充另一个组合框吗?嗨!谢谢回复!否,不使用另一个组合框:-)我想使用在我的组合框中选择的项(contact_grname)过滤我的数据网格
yourCollectionView.Refresh();