我已经用数据表填充了数据网格。我可以用 rowfilter 过滤这个数据表。我搜索产品并得到结果。但我也想获得同一组中的其他产品。
我的代码
<Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="129" Width="124" Loaded="Window_Loaded_1">
<Grid>
<DataGrid x:Name="testGrid" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding GROUP}" Header="GROUP"/>
<DataGridTextColumn Binding="{Binding PRODUCT}" Header="PRODUCT"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Private Sub Window_Loaded_1(sender As Object, e As RoutedEventArgs)
'Create tabel
Dim table As New DataTable
table.Columns.Add("GROUP", GetType(String))
table.Columns.Add("PRODUCT", GetType(String))
table.Rows.Add("Group1", "Printserver")
table.Rows.Add("Group1", "Recupel")
table.Rows.Add("Group2", "Docking")
table.Rows.Add("Group2", "Monitor")
'Set Filter
table.DefaultView.RowFilter = "PRODUCT like '%Monitor%'"
'Fill Datagrid
testGrid.DataContext = table
End Sub
这是我需要的截图:
这将是 ===>
如何使用数据表过滤器做到这一点?