Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用组合框筛选DataGrid_C#_Wpf - Fatal编程技术网

C# 使用组合框筛选DataGrid

C# 使用组合框筛选DataGrid,c#,wpf,C#,Wpf,我正在尝试使用组合框过滤数据网格中的数据 我在xaml中有这个: <ComboBox x:Name="cmbFilter" SelectionChanged="cmbFilter_SelectionChanged" /> <Grid> <DataGrid x:Name="dataList"> <DataGrid.Columns >

我正在尝试使用组合框过滤数据网格中的数据

我在xaml中有这个:

    <ComboBox x:Name="cmbFilter" SelectionChanged="cmbFilter_SelectionChanged" />
       <Grid>
             <DataGrid x:Name="dataList">
                   <DataGrid.Columns >
                       <DataGridTextColumn Header="School" Binding="{Binding SchoolName}"></DataGridTextColumn>
                       <DataGridTextColumn Header="Category" Binding="{Binding CategorySchool}"></DataGridTextColumn>
                   </DataGrid.Columns>
             </DataGrid>
       </Grid>
我设法用所有数据填充DataGrid,并在组合框中设置所有学校名称。 我想要的是能够根据从带有“School”列的组合框中选择的学校名称过滤数据网格。显示的数据仅来自组合框中选择的学校

谢谢

您可以使用
Where()


谢谢你,工作很有魅力!我不能+1你的评论,因为我还没有15个名声。。
//fill the list with the datas
this.dataList.ItemsSource = MainWindow._RE.ListDatas;

//fill the combobox with the school names
this.cmbFilter.ItemsSource = MainWindow._RE.ListNameSchool;

private void cmbFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // ??????
}
private void cmbFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    this.dataList.ItemsSource = MainWindow._RE.ListDatas.Where(i => i.SchoolName == (string)cmbFilter.SelectedItem);
}