下面的示例展示了如何通过 ColumnView.ShowFilterPopupCheckedListBox 事件来定制 复选式筛选下拉列表。 在本示例中,Category Name 列的筛选下拉列表被呈现为一个复选式列表。 在 ShowFilterPopupCheckedListBox 事件中,此列表的“Show All”项被隐藏,并且禁用了两个项 (“Seafood” 和 “Condiments”)。 结果如下图所示:

C#CopyCode image复制代码
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors.Controls;

// Enable the checked filter dropdown list for the Category Name column.
colCategoryName.OptionsFilter.FilterPopupMode = 
    DevExpress.XtraGrid.Columns.FilterPopupMode.CheckedList;
// Subscribe to the ShowFilterPopupCheckedListBox event.
gridView1.ShowFilterPopupCheckedListBox += 
    new FilterPopupCheckedListBoxEventHandler(gridView1_ShowFilterPopupCheckedListBox);

void gridView1_ShowFilterPopupCheckedListBox(object sender, 
    DevExpress.XtraGrid.Views.Grid.FilterPopupCheckedListBoxEventArgs e) {
    if(e.Column.FieldName != "CategoryName") return;
    // Hide the "Show All" item.
    e.CheckedComboBox.ShowAllItemVisible = false;            
    // Locate and disable checked items that contain specific values.
    for(int i =0; i< e.CheckedComboBox.Items.Count; i++) {
        CheckedListBoxItem item = e.CheckedComboBox.Items[i];
        string itemValue = (string)(item.Value as FilterItem).Value;
        if (itemValue == "Seafood" || itemValue == "Condiments") {
            e.CheckedComboBox.Items[i].Enabled = false;
        }
    }
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors.Controls

' Enable the checked filter dropdown list for the Category Name column.
colCategoryName.OptionsFilter.FilterPopupMode = _ 
    DevExpress.XtraGrid.Columns.FilterPopupMode.CheckedList
' Subscribe to the ShowFilterPopupCheckedListBox event.
AddHandler GridView1.ShowFilterPopupCheckedListBox, _ 
    AddressOf gridView1_ShowFilterPopupCheckedListBox

Private Sub gridView1_ShowFilterPopupCheckedListBox(ByVal sender As Object, _ 
ByVal e As FilterPopupCheckedListBoxEventArgs)
    If e.Column.FieldName <> "CategoryName" Then
        Return
    End If
    ' Hide the "Show All" item.
    e.CheckedComboBox.ShowAllItemVisible = False
    ' Locate and disable checked items that contain specific values.
    Dim i As Integer = 0
    Do While i < e.CheckedComboBox.Items.Count
        Dim item As CheckedListBoxItem = e.CheckedComboBox.Items(i)
        Dim itemValue As String = CStr((TryCast(item.Value, FilterItem)).Value)
        If itemValue = "Seafood" OrElse itemValue = "Condiments" Then
            e.CheckedComboBox.Items(i).Enabled = False
        End If
        i += 1
    Loop
End Sub