I'm noticing a very odd behavior with column sorting in the grid. Upfront I will admit we are still on infragistics version 2010.1 (we had a release upcoming and couldn't wait for the multiple group by issue to be fixed)
I have a grid where for one column I have implemeneted a custom grid sorter (of type IComparer) and assigned that to the column's .SortComparer property.
While debugging another operation, I had need to disable all sorting. So in the grid's _BeforeSortChange event I set e.cancel = true;
When I did so, I noticed that clicking on a column header, while not performing a sort, still seemed to lock the UI thread briefly (for a very large dataset, after clicking the column header I was unable to focus any other component for a few seconds).
I put a breakpoint in Visual Studio in the _AfterSortChange event and never hit it.
However, I also put a breakpoint in my custom sort class's Compare() method and that one gets hit.
It *seems* as if, even though the cancel is set to true in the _BeforeSortChange method and no visual sort is performed, the sorting "logic" is still being performed by the grid.
For the record, I am not calling a RefreshSort() anywhere in the grid or in any other way kicking off a manual sort.
Is this behavior intended? If so is there some way I can work around it (besides dynamically adding / removing the sort class from the column).
Thanks,
Chris Rowland
Hello,
This issue is fixed in 10.1.20101.2050 CLR 2.0, 10.2.20102.2043 CLR 2.0 builds.
Thank you,
Hello Chris,
I have logged this issue in our system with a Development Issue ID of 36294.
Hi Chris,
A column has to be sorted in order to be grouped, so I guess in most cases, it would not make sense for the HeaderClickAction to apply to the GroupByButton.
Are you allowing the users to do the grouping or are you doing it in code?
What you can probably do is use a flag that determines whether each change to sorting is allowed. Then you check that flag inside the BeforeSortChange event. Then any time you want to change the sorting in code, you set the flag first, then set the Sortindicator, then set the flag back.
Something like this:
private void ultraGrid1_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e) { switch (e.Header.Column.SortIndicator) { case SortIndicator.Ascending: this.SetSortIndicator(e.Header.Column, SortIndicator.Descending); break; case SortIndicator.None: case SortIndicator.Descending: this.SetSortIndicator(e.Header.Column, SortIndicator.Ascending); break; case SortIndicator.Disabled: break; } } private void SetSortIndicator(UltraGridColumn column, SortIndicator sortIndicator) { this.allowSortChange = true; try { column.SortIndicator = sortIndicator; } finally { this.allowSortChange = false; } } bool allowSortChange = false; private void ultraGrid1_BeforeSortChange(object sender, BeforeSortChangeEventArgs e) { if (false == this.allowSortChange) e.Cancel = true; }
If you need to group a column, you do the same thing with the flag, since grouping a column will fire BeforeSortChange. If you need the users to be able to group the columns, then it becomes a bit more complicated as you will have to put a check in BeforeSortChange to see if the groupings are changing and allow that.
Thanks Mike. That gets me *really close* to what I'm looking for. Single click on the column header is no longer triggering a BeforeSort event, and only fires once on double click.
The only unwanted behavior I'm seeing now is that this doesn't seem to apply to GroupByColumnHeaders when the grid is in ShowGroupBy mode and such a column exists. Single click on the group by column is still performing a sort.
I would think the HeaderClickAction would apply to all column headers but maybe that's not the case?
Thanks
How about turning off the grid's automatic sorting behavior and handling the toggling of the sort indicator yourself using the DoubleClickHeader event.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridOverride ov = layout.Override; // Turn off sorting. ov.HeaderClickAction = HeaderClickAction.Select; // Turn off column selection ov.SelectTypeCol = SelectType.None; } private void ultraGrid1_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e) { switch (e.Header.Column.SortIndicator) { case SortIndicator.Ascending: e.Header.Column.SortIndicator = SortIndicator.Descending; break; case SortIndicator.None: case SortIndicator.Descending: e.Header.Column.SortIndicator = SortIndicator.Ascending; break; case SortIndicator.Disabled: break; } }