Posted 13 February 2024, 4:25 pm EST
We experience some weird behaviour is using sort with a FlexGrid, so I made a sample to see if I could reproduce the weirdness. In doing so, I was able to find a way around the issue, but I think there may be something going on.
To be specific, the problem is that when you click a different column to sort it selects that column as #2 in the sort sequence, instead of only sorting by that column. (as if you had held down Ctrl, but you didn’t)
There are many ways I was able to produce the weird behaviour, the following is 1 of these ways:
-
Launch my sample App.
-
User click on column header “Description” which will sort the grid by “Description” (expected behaviour).
-
Click on button “Sort” which calls grid.Sort(SortFlags.Ascending, 1); This will sort the grid by column 1. (expected behaviour).
-
User click on column header “Description”. This adds Description as #2 in the sort, and does not remove column 1. Column 1 and Description are now part of the sort columns – as if the user held down “Ctrl” but they didn’t. (unexpected behaviour) .
Way Around the Issue
I found that if I call c1FlexGridMultiRange.SortDefinition = null; before calling Sort then the issue does not happen.
Personally I don’t think this is by design due to the order of events, so I thought I would raise the issue.
As mentioned, the issue also occurs in other scenarios - one of which is if I use Sort initially on the BindingSource, and I don’t use flexgrid.sort at all… the user gets the issue when they start clicking columns to sort. So it occurs even if .Sort is not used programmatically, but the BindingSource has a sort preconfigured before binding to the grid.