如何覆盖特殊过滤器操作数“空白”和“非空白”对于 XamDataGrid?
首先:我们使用 infragistics xamdatagrid 11.1.20111.2053
我们的问题:
我们使用带有通用列表的网格。所以它是非常动态的,必须为任何情况做好准备。我们为每个字段类型设置SortComparer、FilterComparer、编辑器类型、Edita类型和样式编辑器。 对于模型的某些属性,我们使用特殊的 TypeConverter。 例如,在单元格中,某些值无法显示。
0 = string.Empty
1 = 1
2 = 2
第一个解决方案,我们只使用类型转换器和一个特殊的排序比较器:
public class HideZeroIntEntryConverter : Int32Converter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if (value is int) {
if (destinationType == typeof(string)) {
return ((int)value != 0) ? value.ToString() : string.Empty;
}
return ((int)value != 0) ? value : Binding.DoNothing; // this is the best solution to tell the grid the cell is empty
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
如果我们不决定过滤,那么这很完美,但如果我们想过滤值,我们会在过滤器下拉项中看到丑陋的“Binding.DoNothing”(排序和过滤也是错误的)。 另外,我们无法过滤“0”,因为转换器说 string.empty...
第二个解决方案,我们使用特殊的 XamTextEditor:
public class HideZeroIntEntryTextEditor : XamTextEditor
{
public HideZeroIntEntryTextEditor() {
this.ValueToDisplayTextConverter = new HideZeroIntEntryValueConverter();
}
}
public class HideZeroIntEntryValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value is int) {
if (targetType == typeof(string)) {
return ((int)value != 0) ? value.ToString() : string.Empty;
}
// this never happens
return ((int)value != 0) ? value : Binding.DoNothing;
}
// this never happens
return targetType == typeof(string) && value != null ? value.ToString() : value;
}
}
对于字段设置
field.Settings.EditAsType = typeof(int);
field.Converter = null;
field.Settings.EditorType = typeof(HideZeroIntEntryTextEditor);
field.Settings.SortComparer = GenericComparer<int>.Instance;
field.Settings.FilterComparer = GenericComparer<int>.Instance;
field.Settings.GroupByComparer = GroupByRecordComparer<int>.Instance;
现在我们可以过滤为“0”,即使这不会出现在列表中。
但是,在这两种情况下,我们都无法按空条目进行过滤,因为它实际上不存在! 但我们想要! 我们认为,如果我们能够制作自己的特殊过滤器,这可能是可行的。但不幸的是这并不那么容易。 是的,我们可以删除特殊的过滤器空白和非空白,但这适用于所有网格。 要覆盖的特殊过滤器非常复杂,甚至不正确。
好的,我们想要看到空单元格,并且想要过滤该单元格,但是特殊过滤器无法正常工作!
我们能做什么,有什么想法吗?
这是 infragistics 的问题
first: we use infragistics xamdatagrid 11.1.20111.2053
our problem:
We use the grid with generic lists. So it's very dynamic and must be prepared for any situation. We set for each field type theSortComparer, FilterComparer, the editor type, Edita type and style editor.
For some properties of a model, we use special TypeConverter.
For example, in a cell, some values ??can not be displayed.
0 = string.Empty
1 = 1
2 = 2
first solution, we only use the type converter and a special sort comparer:
public class HideZeroIntEntryConverter : Int32Converter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if (value is int) {
if (destinationType == typeof(string)) {
return ((int)value != 0) ? value.ToString() : string.Empty;
}
return ((int)value != 0) ? value : Binding.DoNothing; // this is the best solution to tell the grid the cell is empty
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
this works perfect if we not decide to filter, but if we want to filter the values we see the ugly "Binding.DoNothing" in the filter drop down items (the sorting and filtering is also wrong).
also, we can not filter for "0" because we the converter says string.empty...
second solution, we use a special XamTextEditor:
public class HideZeroIntEntryTextEditor : XamTextEditor
{
public HideZeroIntEntryTextEditor() {
this.ValueToDisplayTextConverter = new HideZeroIntEntryValueConverter();
}
}
public class HideZeroIntEntryValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value is int) {
if (targetType == typeof(string)) {
return ((int)value != 0) ? value.ToString() : string.Empty;
}
// this never happens
return ((int)value != 0) ? value : Binding.DoNothing;
}
// this never happens
return targetType == typeof(string) && value != null ? value.ToString() : value;
}
}
and for the field settings
field.Settings.EditAsType = typeof(int);
field.Converter = null;
field.Settings.EditorType = typeof(HideZeroIntEntryTextEditor);
field.Settings.SortComparer = GenericComparer<int>.Instance;
field.Settings.FilterComparer = GenericComparer<int>.Instance;
field.Settings.GroupByComparer = GroupByRecordComparer<int>.Instance;
Now we can filter to "0", even if this does not appear in the list.
But, in both cases, we can not filter by empty entries, because it actually does not exist!
We want to though!
In our opinion, this could be if we could make our own special filter. But this is unfortunately not so easy.
Yes, we can remove the special filter blanks and NonBlanks, BUT that applies to all grids.
A special filter to override is very complicated and does not even correct.
Ok, we want see empty cell, and want filter this cells, but the special filter doesn't works correct!
What can we do, any ideas?
here is the question at infragistics
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 Infragistics 论坛就在这里上用一个示例回答了这个问题。
当字段的编辑器为 HideZeroIntEntryTextEditor 时,您可以使用 RecordFilterDropDownPopulated 事件删除“(Blanks)”的现有 FilterDropDownItem,并将其替换为值为 0 的自定义 FilterDropDownItem。以下代码完成此操作:
I answered this on the Infragistics forums right here with a sample.
You can use the RecordFilterDropDownPopulating event to remove the existing FilterDropDownItem for "(Blanks)" and replace it with a custom one for the value of 0 when the editor for the field is HideZeroIntEntryTextEditor. The following code accomplishes this: