ColumnView.CustomRowFilter Event
Allows you to hide/show specific rows (that exist in the data source) based on a condition regardless of the grid’s filter.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
Event Data
The CustomRowFilter event's data class is RowFilterEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Handled | Gets or sets whether the event is handled and therefore no default processing is required. |
ListSourceRow | Gets the index in the data source of the row currently being processed. Row handles are not data source indexes, see the Accessing Rows in Code. Row Handles section of the “Rows” article for more information. |
Visible | Gets or sets whether the current record must be visible in a View. |
Remarks
By default, the grid displays all rows/records from its data source that match the filter criteria specified by a View (filter criteria are specified by GridColumn.FilterInfo properties of grid columns). Rows that do not match filter criteria are not displayed in the View.
The CustomRowFilter
event allows you to hide/show specific rows based on a specific condition (ignoring filter criteria applied to columns).
The CustomRowFilter
event fires for each record in the data source. The e.ListSourceRow parameter identifies the processed record by its zero-based index.
The the e.Visible parameter specifies whether to show or hide the row.
Set the e.Handled parameter to true to handle the event and cancel default processing. If the e.Handled parameter is set to false, the row’s visibility is determined by the View’s filter.
Important
The CustomRowFilter
event is not supported in Server and Instant Feedback Modes.
Note
The Grid control silently swallow exceptions that are raised within the CustomRowFilter
event handler (if any). The Grid control stops filtering rows and hides all subsequent rows. Enclose the code in the CustomRowFilter
event handler with the try…catch block to catch and re-throw an exception.
Tip
If you need to get or set cell values while handling the CustomRowFilter
event, use methods of the bound data source. The event’s e.ListSourceRowIndex
parameter identifies the processed record. To get record values, use the ColumnView.GetListSourceRowCellValue method or methods of data objects. DO NOT use APIs of the Grid Control that have the rowHandle
parameter (for example, ColumnView.GetRowCellValue).
Example 1: Keep Specific Rows Always Visible
The following code shows how to make the rows that contain the “USA” value in the ‘Country’ field always visible regardless of the filter applied to a View. The ColumnView.CustomRowFilter
event is handled to control the visibility of the rows.
using DevExpress.XtraGrid.Views.Base;
private void gridView1_CustomRowFilter(object sender, RowFilterEventArgs e) {
ColumnView view = sender as ColumnView;
string country = view.GetListSourceRowCellValue(e.ListSourceRow, "Country").ToString();
// Check whether the current row contains "USA" in the "Country" field.
if (country == "USA") {
// Make the current row visible.
e.Visible = true;
// Prevent default processing, so the row will be visible
// regardless of the view's filter.
e.Handled = true;
}
}
Example 2: Hide Specific Rows Based on a Condition
The following example hides the first row in a data source. The example handles the CustomRowFilter
event and sets the e.Visible
property to false
:
void gridView1_CustomRowFilter(object sender, RowFilterEventArgs e) {
if (e.ListSourceRow == 0) {
e.Visible = false;
e.Handled = true;
}
}
Example 3: Toggle Row Visibility
The following GitHub example implements a RowVisibilityHelper
helper class. Its ShowRow
and HideRow
methods allow you to hide/show the specified data row:
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomRowFilter event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.