[]
We already mentioned that it is generally desirable to restrict the data returned from the server to the client, and we demonstrated how C1DataSource 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:
Add a ComboBox control to the form and set the following properties:
Add a DataGrid control to the form and set the following properties:
Add the following code to the form to handle the combo box’s SelectedValueChanged event:
To write code in Visual Basic
Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
c1DataSource1.ViewSources("Products").FilterDescriptors(0).Value = comboBox1.SelectedValue
End Sub
To write code in C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
c1DataSource1.ViewSources["Products"].FilterDescriptors[0].Value = comboBox1.SelectedValue;
}
Add the following code to the Form_Load event, to set the AutoGenerateColumns property, of the dataGridView control to 'true'.
To write code in Visual Basic
dataGridView1.AutoGenerateColumns = True
To write code in C#
dataGridView1.AutoGenerateColumns = true;
Save, build and run the application. Select a category in the combo box and notice how products related to that category are displayed in the grid. Switch between categories and notice how the data is returned. As before, all the items in the grid are editable.