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.
Hello,
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:
void XamDataGrid1_RecordFilterDropDownPopulating(object sender, Infragistics.Windows.DataPresenter.Events.RecordFilterDropDownPopulatingEventArgs e) { if (e.Field.EditorTypeResolved == typeof(HideZeroIntEntryTextEditor)) { bool found = false; int index = 0; while (index < e.DropDownItems.Count && !found) { FilterDropDownItem item = e.DropDownItems[index]; if (item.DisplayText == "(Blanks)") { e.DropDownItems.Remove(item); e.DropDownItems.Insert(index, new FilterDropDownItem(new ComparisonCondition(ComparisonOperator.Equals, 0), "(Blanks)")); found = true; } index++; } } }
I have also attached a sample that demonstrates this.
Let me know if you have any questions with this matter.
that's a pretty simple and cool solution. Thank you.I've posted the code from the forum in your answer at StackOverflow, I hope that's ok.
best regards
jan
I noticed two more things.When changing between empty and non empty, the operator will not reset.
e.DropDownItems.Insert(index, new FilterDropDownItem(new ComparisonCondition(ComparisonOperator.Equals, 0), item.DisplayText));e.DropDownItems.Insert(index, new FilterDropDownItem(new ComparisonCondition(ComparisonOperator.NotEquals, 0), item.DisplayText));
after selecting the non empty item the operator is still equals!
Secondly, I need this solution in a custom filter.Where can I get to manipulate the filters?
Thanks for the help.
Jan,
I was able to reproduce the issue with the condition not changing when changing the filter in the drop down. I will continue to look into this tomorrow.
For the custom filter, the same event allows you to change the operands on the dialog.
Hi,
Thank you for your help.
I have another request.
We save all the settings of the grid itself as xml. We do not use theLoadCustomizations / SaveCustomizastions functions, we wanted to be independent of the grid (which we have already made theUltraGird, we had to keep the xml format as we switched to WPF). We get the point somehow, but there are problems with saving and loading the filter.
If we now execute the following code, then the value is not in the filter cell, but the tooltip (is this a bug?)
var recordFilter = new RecordFilter { FieldName = xFieldName };recordFilter.Conditions.LogicalOperator = LogicalOperator.And;recordFilter.Conditions.Add(new ComparisonCondition(ComparisonOperator.Equals, SpecialFilterOperands.Blanks));fieldLayout.RecordFilters.Add(recordFilter); The same effect happens with the special HideZeroIntEntry filter. You can only specify the following var recordFilter = new RecordFilter { FieldName = xFieldName }; recordFilter.Conditions.LogicalOperator = LogicalOperator.And; // the special filter to 0 = 'Blanks' must be displayed but '0' are shown! recordFilter.Conditions.Add(new ComparisonCondition(ComparisonOperator.Equals, 0)); fieldLayout.RecordFilters.Add(recordFilter); How can we change the value displayed in the filter cell? Is that even possible? best regards Jan
var recordFilter = new RecordFilter { FieldName = xFieldName };recordFilter.Conditions.LogicalOperator = LogicalOperator.And;recordFilter.Conditions.Add(new ComparisonCondition(ComparisonOperator.Equals, SpecialFilterOperands.Blanks));fieldLayout.RecordFilters.Add(recordFilter);