ColumnView.CustomRowFilter Event

Allows you to hide particular rows that exist in the data source or make them visible (regardless of the grid's filter).

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("Data")]
public event RowFilterEventHandler CustomRowFilter
<DXCategory("Data")>
Public Event CustomRowFilter As RowFilterEventHandler

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 the records from a data source that match the filter criteria specified by a View (the filter criteria are specified by the GridColumn.FilterInfo properties of the View's columns). The records that do not match these criteria are not displayed.

The CustomRowFilter event provides a more flexible way to control a record's visibility in a View. It can be handled to hide specific records (even if they match the current filter criteria) or make particular records visible (even if they do not match the current criteria).

This event fires for each record. The currently processed record is identified by the RowFilterEventArgs.ListSourceRow parameter, and this specifies the record's zero-based index in the data source.

Set the RowFilterEventArgs.Visible parameter to false and the RowFilterEventArgs.Handled parameter to true to hide the currently processed record.

To make the record visible regardless of the View's filter, set both the RowFilterEventArgs.Visible and RowFilterEventArgs.Handled parameters to true.

If the RowFilterEventArgs.Handled parameter is set to false the record's visibility will be determined by the filter that is applied to the View. That is, the record will be visible only if it matches the filter. Otherwise, it will be hidden.

NOTE

If you need to get or set specific cell values while handling the CustomRowFilter event, use methods provided by the bound data source. The event's ListSourceRowIndex parameter allows you to identify the current data row. To get values in a specific row in the data source, you can use the ColumnView.GetListSourceRowCellValue method or methods provided by row objects. To get cell values, do not use methods provided by the Grid Control that have a rowHandle parameter (e.g., ColumnView.GetRowCellValue).

NOTE

The CustomRowFilter event is not supported in Large Data Sources: Server and Instant Feedback Modes.

NOTE

If an exception is raised within a CustomRowFilter event handler, it is silently swallowed by the grid control. In addition, the grid stops filtering rows and all subsequent rows will be hidden. To catch and re-throw an exception that might occur within the CustomRowFilter event handler, enclose the code in your CustomRowFilter event handler with the try...catch block.

Examples

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;
    }
}
See Also