hi,
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.Empty1 = 12 = 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, if we want to filter the values we see the ugly "Binding.DoNothing" in the filter drop down items.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.
If
What can we do, any ideas?
Best regards.
Vijay,
You could create a behavior that handles the event and put the logic there instead of handling the event in the code behind. The Behavior<T> class is in the System.Windows.Interactivity assembly provided with Blend 4.0.
Devin provided an example on his blog with behaviors to provide a bindable selected items collection in Silverlight and the approach would be similar for writing a behavior in WPF.
Note that if you don't have blend, you can get the assembly from the Microsoft Expression Blend SDK for .NET 4.
Let me know if you have any questions with this matter.
Is there anyway we can do remove the filter operands through binding? Basically, I want to remove all the operands and keep only Contains / Does Not Contain operands in the XAML or from the view model in MVVM pattern.
Thanks,
Vijay
Jan,
I have logged the behavior with the filter not being applied correctly on the custom dialog that I mentioned in my last post as development issue 102165 and have provided more details through case CAS-84216-DMZT25. I have also logged development issue 102170 for the logic in the ToString method of SpecialFilterOperandBase and provided details on this through case CAS-84216-DMZT25.
You will be notified through the case of the resolutions of the development issues and then I will also post the resolution here when they are resolved.
Sincerely,AlanDeveloper Support SupervisorInfragisticswww.infragistics.com/support
Hi,
Thanks again for the help.
I tried the solution, it works when the custom filter dialog opens for the first time and then selects its own special filter.But if this dialogue is the second time opened with the current filter, then the filter cells have the wrong values again.
wrong: "0"right: "Custom Blanks"
the lable at the bottom shows also the wrong text: e.g. '= 0 OR = 3' instead 'Blanks' OR = 3'
Second, I think that I have found a bug in the ToString () method of SpecialFilterOperandBase.
public override string ToString(){ return (this.DisplayContent as string ?? this.Description as string) ?? base.ToString();}
The problem is that the display content is not a string!
The immediate window give me following output:
((SpecialFilterOperandBase)compValue).DisplayContent.GetType()FullName: "Infragistics.Windows.Controls.SpecialFilterOperandFactory+IGOperand+FormattedSRValue"
And you can see, it's not a string and this expression is always 'null'.
---> this.DisplayContent as string
I think this change would solve the problem.
public override string ToString() {
var displayContent = this.DisplayContent != null ? this.DisplayContent.ToString() : null;
var description = this.Description != null ? this.Description.ToString() : null;
return (displayContent ?? description) ?? base.ToString();
}
For the issue with not being able to change the filters, I have logged development issue 101703 for this and provided you with more details through case CAS-84216-DMZT25.
For the question about changing the text of the filters on the custom dialog, you can do this by creating your own classes to represent the ComparisonCondition and then override the ToString method to provide the details that you want.
For example:
public class HideZeroBlanksComparisonCondition : ComparisonCondition { public HideZeroBlanksComparisonCondition() : base(ComparisonOperator.Equals, 0) { } public override string ToString() { return "Blanks"; } }
With that you would add the filter with the following code:
e.DropDownItems.Insert(index, new FilterDropDownItem(new HideZeroBlanksComparisonCondition(), "(Custom Blanks)"));
I have also attached an updated sample that shows this.
Note that there is still some unusual behavior when you select both options where the incorrect values will show. This I am still looking into and will follow up when I have more information.
Let me know if you have any questions.