Back to Devexpress

VGridControl.FilterPopupExcelData Event

windowsforms-devexpress-dot-xtraverticalgrid-dot-vgridcontrol-9c48b636.md

latest6.3 KB
Original Source

VGridControl.FilterPopupExcelData Event

Allows you to add, remove, and modify data values and customize predefined filters in the Excel style pop-up filter menus. Filter items added manually on this event must be unique and sorted.

Namespace : DevExpress.XtraVerticalGrid

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

csharp
[DXCategory("Behavior")]
public event FilterPopupExcelDataEventHandler FilterPopupExcelData
vb
<DXCategory("Behavior")>
Public Event FilterPopupExcelData As FilterPopupExcelDataEventHandler

Event Data

The FilterPopupExcelData event's data class is DevExpress.XtraVerticalGrid.FilterPopupExcelDataEventArgs.

Examples

A default column filter menu contains data values available in the column. The code below shows how to populate a filter menu with custom values.

Note

The example uses the grid control. The vertical grid, tree list, and pivot grid controls provide a similar API.

In this example, the processed column contains comma-separated values that can be treated as individual tokens. The FilterPopupExcelData event allows you to populate the menu with custom tokens instead of the available data values.

csharp
readonly static char[] separators = new char[] { ',', ' ' };

void OnFilterPopupExcelData(object sender, FilterPopupExcelDataEventArgs e) {
    // Create a collection of tokens based on data values.
    var tokens = new HashSet<string>();
    for(int i = 0; i < e.Values.Length; i++) {
        var parts = ((string)e.Values[i]).Split(separators, StringSplitOptions.RemoveEmptyEntries);
        for(int j = 0; j < parts.Length; j++)
            tokens.Add(parts[j]);
    }
    // Remove the default data values from the filter menu.
    e.ClearData();
    // Populate the menu with the created tokens.
    foreach(string t in tokens.OrderBy(x => x))
        e.AddData(t, t);
}
vb
Private ReadOnly Shared separators() As Char = { ","c, " "c }

Private Sub OnFilterPopupExcelData(ByVal sender As Object, ByVal e As FilterPopupExcelDataEventArgs)
    ' Create a collection of tokens based on data values.
    Dim tokens = New HashSet(Of String)()
    For i As Integer = 0 To e.Values.Length - 1
        Dim parts = DirectCast(e.Values(i), String).Split(separators, StringSplitOptions.RemoveEmptyEntries)
        For j As Integer = 0 To parts.Length - 1
            tokens.Add(parts(j))
        Next j
    Next i
    ' Remove the default data values from the filter menu.
    e.ClearData()
    ' Populate the menu with the created tokens.
    For Each t As String In tokens.OrderBy(Function(x) x)
        e.AddData(t, t)
    Next t
End Sub

If you have populated the menu with custom tokens, you also must handle the following events:

  • FilterPopupExcelQueryFilterCriteria — to convert the selected tokens to the corresponding filter criteria that should be applied to data (direct conversion). This conversion is processed when the user selects a token in the menu/applies the selected tokens/closes the menu.

  • FilterPopupExcelParseFilterCriteria — to convert the applied filter criteria to the corresponding tokens that should be selected in the menu (reverse conversion). This conversion is processed when the user opens the menu.

The code snippet below shows how to handle the FilterPopupExcelData event to add custom filters for a particular column.

csharp
private void vGridControl1_FilterPopupExcelData(object sender, DevExpress.XtraVerticalGrid.FilterPopupExcelDataEventArgs e) {
    string fieldName = e.Column.Row.Properties.FieldName;
    if (e.Column.Row == rowCountry) {
        e.AddFilter("Europe", "[" + fieldName + "] = 'France' OR [" + fieldName + "] = 'Germany'");
        e.AddFilter("North America", "[" + fieldName + "] = 'Canada' OR [" + fieldName + "] = 'Mexico'");
        e.AddFilter("South America", "[" + fieldName + "] = 'Argentina' OR [" + fieldName + "] = 'Brazil'");
    }
}
vb
Private Sub VGridControl1_FilterPopupExcelData(sender As Object, e As DevExpress.XtraVerticalGrid.FilterPopupExcelDataEventArgs) Handles VGridControl1.FilterPopupExcelData
    Dim fieldName As String = e.Column.Row.Properties.FieldName
    If e.Column.Row.Equals(rowCountry) Then
        e.AddFilter("Europe", "[" + fieldName + "] = 'France' OR [" + fieldName + "] = 'Germany'")
        e.AddFilter("North America", "[" + fieldName + "] = 'Canada' OR [" + fieldName + "] = 'Mexico'")
        e.AddFilter("South America", "[" + fieldName + "] = 'Argentina' OR [" + fieldName + "] = 'Brazil'")
    End If
End Sub

See Also

FilterPopupExcelParseFilterCriteria

FilterPopupExcelQueryFilterCriteria

Filtering

VGridControl Class

VGridControl Members

DevExpress.XtraVerticalGrid Namespace