效果图
点击OrderPrice这一列的筛选按钮,出现一个复选框的下拉列表,通过勾选实现过滤功能
实现:
第一步:添加一个GridControl,设置在父容器中停靠,在表单的Load事件中代码如下
private void XtraGridCustomizeCheckedFilterMenuDemo_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“jWDBDataSet3.tb_order”中。您可以根据需要移动或删除它。
this.tb_orderTableAdapter.Fill(this.jWDBDataSet3.tb_order);
colorderPrice.OptionsFilter.FilterPopupMode = DevExpress.XtraGrid.Columns.FilterPopupMode.CheckedList;
gridView1.ShowFilterPopupCheckedListBox += new FilterPopupCheckedListBoxEventHandler(gridView1_ShowFilterPopupCheckedListBox);
}
第二步:实现gridView1_ShowFilterPopupCheckedListBox事件
private void gridView1_ShowFilterPopupCheckedListBox(object sender, DevExpress.XtraGrid.Views.Grid.FilterPopupCheckedListBoxEventArgs e)
{
if (e.Column.FieldName != "orderPrice") return;
e.CheckedComboBox.SelectAllItemVisible = false;
for (int i = 0; i < e.CheckedComboBox.Items.Count; i++) {
CheckedListBoxItem item = e.CheckedComboBox.Items[i];
Decimal itemValue = (decimal)(item.Value as FilterItem).Value;
if (itemValue == 8 || itemValue == 10) {
e.CheckedComboBox.Items[i].Enabled = false;
}
}
}