【发布时间】:2015-08-10 14:49:39
【问题描述】:
我添加了一个以 RepositoryItemCheckedComboBoxEdit 作为编辑器的列。该列的每一行可以包含一个或多个来自预定义类别列表(我们称它们为 Category1、Category2 和 Category3)的条目,这些条目是字符串并从数据库中读取。
我的问题是过滤器将列出选项,例如:“Category1;Category2”以及“Category1”或“Category1;Category2;Category3”,具体取决于它在网格中为所述列找到的内容(如果其中之一这些行选择了所有三个类别,这些类别将被视为单个过滤器选项,而不是将值分解为其组件)。
我希望过滤器只列出单个值,而不是组合,但我无法找到解决方案。我曾尝试使用 ShowFilterPopupCheckedListBox 事件来操作过滤器内容,但现在该列的过滤功能已完全停止。
这是我的代码:
void gridView_ShowFilterPopupCheckedListBox(object sender, DevExpress.XtraGrid.Views.Grid.FilterPopupCheckedListBoxEventArgs e)
{
List<CheckedListBoxItem> atomicValues = new List<CheckedListBoxItem>();
if (e.Column.FieldName != "CategoryCollection") { return; }
for (int i = 0; i < e.CheckedComboBox.Items.Count; i++)
{
CheckedListBoxItem item = e.CheckedComboBox.Items[i];
string itemValue = (string)(item.Value as FilterItem).Value;
string[] atomicItemValues = itemValue.Split(';');
foreach (string atomicValue in atomicItemValues)
{
string trimmedAtomicValue = atomicValue.Trim();
atomicValues.Add(new CheckedListBoxItem(trimmedAtomicValue));
}
}
List<CheckedListBoxItem> distinctAtomicValues = atomicValues.GroupBy(x => x.Value).Select(group => group.First()).OrderBy(x => x.Value).ToList();
e.CheckedComboBox.Items.Clear();
foreach (CheckedListBoxItem atomicItem in distinctAtomicValues)
{
e.CheckedComboBox.Items.Add(atomicItem);
}
}
【问题讨论】:
标签: c# winforms devexpress