DataSource for Entity Framework in WPF > Server-Side Filtering |
We already mentioned that it is generally desirable to restrict the data returned from the server to the client and we demonstrated how C1DataSource|tag=C1DataSource_Class facilitates this with the use of the FilterDescriptor Collection Editor. Now we’ll demonstrate how to provide the end user with the means to achieve server-side filtering.
The user will select a Product Category from a combo box, for example, although other GUI controls can be used, and that will load a DataGrid with new data from the server.
To implement server-side filtering, follow these steps:
<DataGrid AutoGenerateColumns="True" …
ItemsSource="{Binding ElementName=c1DataSource1, Path=Categories}"
DisplayMemberPath="CategoryName"
Just as with the grid and other controls, you can use the binding designer in the Properties window where you can choose from lists, or you can enter the binding directly in XAML.
Visual Basic Copy Code Private Sub comboBox1_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) c1DataSource1.ViewSources("Products").FilterDescriptors(0).Value = CType(comboBox1.SelectedValue, Category).CategoryID c1DataSource1.ViewSources("Products").Load() End Sub
C# Copy Code private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { c1DataSource1.ViewSources["Products"].FilterDescriptors[0].Value = ((Category)comboBox1.SelectedItem).CategoryID; c1DataSource1.ViewSources["Products"].Load(); }