Back to Devexpress

FilterItem Class

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-31f769fe.md

latest3.8 KB
Original Source

FilterItem Class

Represents an individual item within a filter dropdown list.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
[DataPrimitive]
public class FilterItem
vb
<DataPrimitive>
Public Class FilterItem

Remarks

The FilterItem class introduces two properties providing settings for a single filter dropdown’s item. The FilterItem.Text property value is the text representing the filter item within the filter dropdown list. The FilterItem.Value property specifies the filter’s value. When choosing an item within the filter dropdown, the item’s filter value is compared to column values. Only records whose column values match the filter value are displayed within the View as a result.

Filter dropdown items can be accessed by handling the ColumnView.ShowFilterPopupListBox event.

Example

The following code demonstrates how to use the ColumnView.ShowFilterPopupListBox event to customize a “City” column’s filter dropdown list.

First, all default items are removed from the column’s filter dropdown list. Then, a list of FilterItem objects is defined and added to the filter dropdown. Each FilterItem object specifies filter display text and filter value.

The following image shows the grid control after the “City 3” element is selected in the filter dropdown. When this element is selected, the “[City] = ‘Paris’ filter is applied to the grid.

csharp
using DevExpress.XtraGrid.Views.Grid;

private void gridView1_ShowFilterPopupListBox(object sender, DevExpress.XtraGrid.Views.Grid.FilterPopupListBoxEventArgs e) {
    if (e.Column.FieldName != "City") return;
    e.ComboBox.Items.Clear();
    List<FilterItem> filterItemList = new List<FilterItem>();
    filterItemList.Add(new FilterItem("City 1", "Berlin"));
    filterItemList.Add(new FilterItem("City 2", "London"));
    filterItemList.Add(new FilterItem("City 3", "Paris"));
    e.ComboBox.Items.AddRange(filterItemList);
}
vb
Imports DevExpress.XtraGrid.Views.Grid

Private Sub GridView1_ShowFilterPopupListBox(ByVal sender As System.Object, _
  ByVal e As FilterPopupListBoxEventArgs) Handles GridView1.ShowFilterPopupListBox
    If e.Column.FieldName <> "City" Then
        Return
    End If
    e.ComboBox.Items.Clear()
    Dim filterItemList As New List(Of FilterItem)()
    filterItemList.Add(New FilterItem("City 1", "Berlin"))
    filterItemList.Add(New FilterItem("City 2", "London"))
    filterItemList.Add(New FilterItem("City 3", "Paris"))
    e.ComboBox.Items.AddRange(filterItemList)
End Sub

Inheritance

Object FilterItem

See Also

FilterItem Members

DevExpress.XtraGrid.Views.Grid Namespace