One of the columns of my UltraGrid uses a ValueList from int to string to display the record label on the screen for the related id as integer.
A record has the label "0830 (0800)". When I enter "08" in the filter of that column, that row is filtered out. The tooltip on the filter cell displays "Contains '8'".
I changed the column.FilterComparisonStyle to DisplayTextOnly, but this behavior is still the same.
My goal is to filter only for the DisplayText and ignore the values of the ValueList.
How can I accomplish this?
Hello Burak,
I don't see a reason why this wouldn't work. Which version of Infragistics are you using? It's possible that what your seeing is a bug.
We are using 15.2 and 18.2. We see the same behavior on both versions.
Thank you for your answer, Mike.
The line below caused the unwanted behavior.
ultraGrid.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.Edit;
I commented it out and now it's ok, but I have another problem. Now, I see a dropdown when I activate the filter cell.
I need the previous behavior of a simple ultragridcell without a dropdown. Do you have any idea how I can achieve this?
Hm, that's odd. I'm not sure why switching the FilterOperandStyle to Edit causes a change in the filtering behavior. that seems like it might be a bug.
FilterOperandStyle basically changes the editor user by the filter cell from an EditorWithCombo (which is the default) to an EditorWithText. So just as a test, I tried assigning an EditorWithCombo to each cell in the filter row and I turned off the DropDown button in the editor. So I did this at the bottom of the InitializeLayout event.
var editorWithCombo = new EditorWithCombo(); editorWithCombo.ButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never; foreach (var filterCell in layout.Rows.FilterRow.Cells) { filterCell.Editor = editorWithCombo; }
This seems to work, but as I said, I'm not really sure why the problem is occurring in the first place or exactly why this fixes it.
Another potential option would be to leave the Editor alone and use a CreationFilter to remove the dropdown button UIElement in each Filter cell. That's a little more complicated, but it's probably safer. The CreationFilter class would look something like this.
internal class NoDropDownButtonInFilterCellsCreationFilter : IUIElementCreationFilter { public void AfterCreateChildElements(UIElement parent) { if (parent is EditorWithComboUIElement) { var cell = parent.GetContext(typeof(UltraGridCell)) as UltraGridCell; if (cell == null || false == cell.IsFilterRowCell) { return; } var editorWithTextUIElement = parent.GetDescendant(typeof(EditorWithTextUIElement)); var editorWithComboDropDownButtonUIElement = parent.GetDescendant(typeof(EditorWithComboDropDownButtonUIElement)); if (null == editorWithTextUIElement || null == editorWithComboDropDownButtonUIElement) { return; } editorWithTextUIElement.Rect = parent.RectInsideBorders; // We could remove this element, but it's probably safer just to give it // an empty rect so the user can't click on it. editorWithComboDropDownButtonUIElement.Rect = Rectangle.Empty; } } public bool BeforeCreateChildElements(UIElement parent) { // Do nothing return false; } }
And you hook it up to the grid like so:
this.ultraGrid1.CreationFilter = new NoDropDownButtonInFilterCellsCreationFilter();
Frankly, though... I'm not sure why you want to remove the dropdown entirely. Why not left the user choose a value from the list in the filter cell? I can see how it might not make sense to have things like Custom or Blanks on there, but you can easily remove those using the FitlerDropDownItems property.
Thank you for the detailed answer, Mike.
I tried with the project you provided and see all kinds of unexpected behavior.
I added the following line of code in ultraGrid1_InitializeLayout.
ov.FilterOperandStyle = FilterOperandStyle.Edit;
And extended the value list with the following.
vl.ValueListItems.Add(5, "add 08:12");
When I enter '0' in the filter cell, the grid is completely empty. All rows are filtered. Expected values are "0830 (0800)" and "add 08:12".
When I enter '1' in the filter cell: Expected: "add 08:12". Actual: "Banana"
When I enter '2' in the filter cell: Expected: "add 08:12". Actual: "Cherry"
When I enter '3' in the filter cell: Expected: "0830 (0800)". Actual: "Grape"
When I enter '8' in the filter cell: Expected and actual values match: "0830 (0800)" and "add 08:12".
At this moment, I'm not allowed to make any changes to the functionality of the software, but only fix bugs.
Hi Burak,
Well... I'm a little confused. Maybe I wasn't clear, but if you are going to use either of the workarounds I suggested (setting the editor or using the CreationFilter), you can't set the FilterOperandStyle to Edit. Once you do that, it doesn't work and you get the original problem. So you should leave that set to Default and then use one of the other approaches I mentioned to remove the dropdown button.
Ok, thank you for your answers. EditorWithCombo seems to be our best solution. I'll discuss this with our team.
I expect you have probably moved on from this, but we have looked into the issue more deeply and the underlying cause is extremely complex and so the developers have decided it would be too dangerous to "fix" it in the control.
However, I have discovered that one root of the problem is that when you use FilterOperandStyle.Edit, the filter cell converts what you type to the DataType of the column. So the filter condition is looking for a Numeric zero instead of a string zero. And then the filter itself ends up running that value through the ValueList and looking for the wrong test entirely.
The practical implications of that is that there's another potential workaround. If, for some reason, you don't like the other workarounds I gave you and you really want to set the FilterOperandStyle.Edit, you can still make the filter work correctly by forcing the filter conditions for the column to always use a string.
private void UltraGrid1_BeforeRowFilterChanged(object sender, BeforeRowFilterChangedEventArgs e) { if (e.NewColumnFilter.Column.Key == "Int32 1") { foreach (FilterCondition filterCondition in e.NewColumnFilter.FilterConditions) { if (!(filterCondition.CompareValue is string)) filterCondition.CompareValue = filterCondition.CompareValue.ToString(); } } }
Thank you for the tip, Mike.
We haven't moved on with this issue. It's currently on hold. So, we are open to ideas and fixes from your side.
Unfortunately, the fix above didn't solve all the cases.
"0" => Solved
Any integer value that doesn't start with 0 => Solved
"0X" where X is an integer => filter key is resolved to X, and the filtering is executed with the query "contains 'X'" instead of "contains '0X'".
Unfortunately, we have many clients that use record labels in the form of "0X:YZ abc" where XYZ are all integers.
I'm confused. I have attached here the sample I have been using to test this. In my sample, there's an item in the ValueList with text: "0830 (0800)" - which is the text you used in your original post.
So if I understand you correctly, you are saying that using the latest workaround I posted, if you type an "8" into the filter cell, it doesn't work and cells that contain "0830 (0800)" are filtered out when they should not be.
But I tried this out with my sample and it works fine. So what am I missing here?
4812.WindowsFormsApplication49.zip
Hi Mike,
Sorry for providing you with incomplete information.
The cells that contain "0830 (0800)" aren't filtered out. They are kept on the grid, which is expected behavior.
The problem is that there are other cells that contain the char '8', but not the string '08'. They are displayed as well when they should be filtered out.
Example: a cell that contains 'abc 8:45' isn't filtered out when I type in '08' in the filter cell. In this case the filter query reads as "contains '8'".
Oh, I see. That makes sense, since the filter cell will convert "08" into a numeric value of 8 and thus lose the 0. So I guess that third workaround is no good and you will need to use one of the other two. Sorry for the confusion, I never thought about leading zeroes.