How to get the Filtered data from the DevExpress Datagrid ?

Here I would like to share with you a code snippet to get only the filtered data from the DevExpress Datagrid. We know that there is an option in GridControl to set the AutoFilterRow as True so that we can filter out the contents easily. But when we are exporting the data, the whole contents will be exported, not just the filtered content. To avoid this, write the following code.

Learn how to get the Filtered data from the DevExpress Datagrid?

Here, we are reading the data from database in the function GetDataFromDatabase() and storing it in the dataset, ds. Then we are displaying it on to the datagrid. (This code may be written in the Read button.)

Dim ds As New DataSet
Dim dv As DataView
ds = GetDataFromDatabase()
Dim dvManager As New DataViewManager(ds)
dv = dvManager.CreateDataView(ds.Tables(0))
GridControl1.DataSource = dv

We are copying the data in datagrid on to another table, dtRecords. (whole data read from the database will be there.)

If ActiveFilterCriteria is present, then the filtered contents is copied to dtRecords.

Dim dtRecords As DataTable = dv.ToTable

If Not (IsNothing(GridView1.ActiveFilterCriteria)) Then
Dim filteredDataView As New DataView(dtRecords)
filteredDataView.RowFilter = DevExpress.Data.Filtering.CriteriaToWhereClauseHelper.GetDataSetWhere(GridView1.ActiveFilterCriteria)
dtRecords = filteredDataView.ToTable
End If

We could set the AutoFilterRow as True by clicking 'Run Designer' in GridControl1 -> 'Feature Browser' on the left hand side -> 'Filtering' -> In its Properties 'OptionsView' -> set 'ShowAutoFilterRow' as True


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: