Hi
I and trying out the filters on the ultragrid. I. There are various filters available and they are really good but, I have a couple of issues, see screenshot
my first issue is the drop down on the right showing the other column names , I don's understand why so how do I get rid of those?
my second bigger issue is why is there no date picker, if i want to do dates between I don't want to have to use a drop down i just want to pick the dates nice and quickly from a date picker.
I believe I can remove some options form the filter drop down when clicking on the filter in the column header
so I would remove Between, and Equals, basically I would only leave 2 items that open that custom UI, Before..... and After...... then, instead of opening the CustomUI just open a pop up with a date time picker in.
Can I do this?
What I don't want to do at any cost, is have them separate on the form. If I go that route then there is no point using any of the filters as it will all be too inconsistent.
Any other suggestions are also helpful, I really like the filter row, but that's no use for dates in my app so I might put a toggle button in my tool bar to toggle between no filters, simple filters (the filter row option as its brilliant for text) and then advanced filters which will be the ones above.
Thanks very much
Paul
I think I have found out, it seems it may be fairly easy as this:
this.filter = new UltraGridFilterUIProvider();this.filter.ButtonToolClick += Filter_ButtonToolClick; this.Grid.DisplayLayout.Override.FilterUIProvider = this.filter;
private void Filter_ButtonToolClick(object sender, ButtonToolClickEventArgs e) { e.Handled = true; Form frm = new Form(); frm.Show(); }
that was just my test which opens a blank form. So I just need to test e.Tool.ID for "Between" and show my own form with date from and to and the datepicker controls, then fill in e.ColumnFilter.
Is that it?
Thanks
Hello Paul,
Thank you for the post. All of the items shown in the Enhanced filtering UI are tools that appear in a menu created through the concept of FilterTool. These tools can be rearranged, removed or new tools can be added through the BeforeMenuPopulate and AfterMenuPopulate events on the WinGridFilterUIProvider.
When a new tool is added, the required action that has to be performed when the tool is clicked should also be taken care of. This can be achieved by handling the ButtonToolClick event of the UltraGridFilterUIProvider and using the event arguments to determine which tool was clicked and then take the appropriate action.
I believe you can refer to this online help document to achieve your requirement.
https://www.infragistics.com/help/winforms/wingridfilteruiprovider-adding-a-custom-filter-to-enhanced-filtering-ui-on-a-wingrid
Let me know if you have any question.
Sincerely,
Divya Jain
Hi Divya
I have two questions...
In the Custom UI dialog why are the other column names appearing in the criteria as in my first screen shot where it has Greater than or Equal to and the first options are other column names? Makes no sense.
Second, why is there no Date Time Picker, it just shows a drop down of all the dates that are in the grid? Is there an option to allow the date picker to be used?
Hi Paul,
Paul Syvret said:In the Custom UI dialog why are the other column names appearing in the criteria as in my first screen shot where it has Greater than or Equal to and the first options are other column names? Makes no sense.
The idea here is that you could apply a filter to this column relative the value of some other column. So, for example, could do something like filter rows where the values in column X are greater than the values in column Y.
As for why those items are shown first, I'm not sure. I suppose that was either some arbitrary decision or it was modeled after some other application like Excel. I checked the latest version of Excel and it doesn't have those other columns listed, so maybe it was some older version of Excel. I think if you are going to have those items, you want them at the top of the list, like any other "special" items. Because the list of unique values could be quite long and so it would be hard to know those items were there if you had to scroll down to the bottom of a very long list.
Anyway, if you want get rid of these, you can do this:
private void UltraGrid1_AfterRowFilterDropDownPopulate(object sender, AfterRowFilterDropDownPopulateEventArgs e) { var valueList = e.ValueList; var valueListItems = valueList.ValueListItems; for (int i= valueListItems.Count - 1; i >=0; i-- ) { var valueListItem = valueListItems[i]; if (valueListItem.DataValue.GetType().Name == "ColumnValueListDataValue") valueListItems.RemoveAt(i); } }
Paul Syvret said:Second, why is there no Date Time Picker, it just shows a drop down of all the dates that are in the grid? Is there an option to allow the date picker to be used?
No, there's no option to use a DatePicker on the custom filter dialog.
Having a DateTimeEditor there would mean you could not have a dropdown list and you could not include all of the special items like the other columns, "(Blanks)", "(NoneBlanks)", "(Errors)", etc. The way Excel deals with that is by having the dropdown list and then also displaying a Button with a DateTime picker next to it.
In theory, you might be able to implement that, but there's no built-in way to do it right now.
The list of filter conditions in the dialog is, in fact, a WinGrid control. So you could handle the BeforeCustomRowFilterDialog event of the grid, get the grid control and add a column to it. But it would be something of a hack to modify the dialog. And it's really not the intended use - there might be code in the dialog that is fighting you and prevents you from doing this. You would also have to jump through some hoops to remove/add that extra column based on the DataType of the column being filters. You would also have to somehow make that column into a DropDown without an edit portion. And handle the events for what happens when the user picks a data. It would be a lot of code. I took a shot at the barest beginnings of what this might look like. I only got as far as adding the date column itself. But you'd have to take it from there.
private void UltraGrid1_BeforeCustomRowFilterDialog(object sender, BeforeCustomRowFilterDialogEventArgs e) { ShowControlTree(e.CustomRowFiltersDialog); var dialog = e.CustomRowFiltersDialog; var gridPanel = dialog.Controls.Find("gridPanel", true)[0]; var grid = gridPanel.Controls[0] as UltraGrid; var band = grid.DisplayLayout.Bands[0]; bool dateColumnExists = band.Columns.Exists("DateTimePicker"); bool isDateTimeFilter = e.Column.DataType.IsAssignableFrom(typeof(DateTime)); if (isDateTimeFilter) { if (false == dateColumnExists) { var dateTimeColumn = band.Columns.Add("DateTimePicker"); dateTimeColumn.DataType = typeof(DateTime); } } else if (dateColumnExists) { band.Columns.Remove("DateTimePicker"); } }
Thanks Mike, first answer is great.
Second answer I want to experiment with later but first you call ShowControlTree. Where do I find this method in the grid api?
Edit: Does calling that even do anything? Mine seems to be fine with it commented out, I still get all the tree options for dates in the main menu and then the custom options
Also, what I have done which seems to work nicely is simply update the "Operand" cell value after the date picker cell is updated (i will probably move that to another event i.e. DatePicker datechanged so user doesn't have to tab out). I might then hide the original column from view, at least I don't have to worry about getting the value into the custom filter filters expression as that is now done for me ;)
I suppose the only "nice to have" is if I leave the drop down it displays the time part even thought i only sent the date part of the datetime. I am probably going to hide it. All this has to be agreed anyway as I mentioned earlier we used to have the filters separate, having them in the grid will speed up the migration to dot net massively but if the clients wont have it then I am in a bind, I am just trying to appease them the best I can. I can let them have the Group by options in exchange for the filters being moved ;)
Oops. I thought I had removed "ShowControlTree." You don't need that. It's not in the API. That's a method I wrote to recursively walk over the controls and display them in the output window. It's just a helpful little method so I can see what the controls on the dialog are so I know what I am looking for when I try to modify controls at run-time. If you are interested, here's the code:
private void ShowControlTree(Control control) { string controlName = control.Name; if (string.IsNullOrEmpty(controlName)) controlName = "(No Name)"; var controlToString = control.ToString(); Debug.WriteLine(controlToString, controlName); Debug.Indent(); foreach (Control childControl in control.Controls) { this.ShowControlTree(childControl); } Debug.Unindent(); }
That's useful, thanks for sharing