I need to perform custom sorting on my grid's data. So I trap the HeaderClickAction to Select and the SelectTypeCol to None, to disable automatic grid sorting. Then I trap the MouseDown click event to determine if and when the user has clicked on a column header. This allows me to sort data the way I need to.
I'd like to continue to use the Sort Indicators (the small up/down triangles in the column headers of sorted columns) that are built in to the UltraWinGrid. But it seems that setting the SortIndicator value not only draws these triangles, but also actually causes the grid to sort the data.
Is it possible to separate the Indicator from the sorting action itself? In other words, is there a way I can set the SortIndicator images in the column headers without causing the grid to try to sort the data?
Or, do I have to draw them myself, as described in KB05873?
The grid's DisplayLayout.Override.HeaderClickAction can be set to ExternalSortSingle or ExternalSortMulti. These two settings allow the grid to be sorted externally from the grid. That is, instead of having the grid control automatically perform the sorting, we can write code to perform custom sorting.
I'm using external sorting to prevent the grid control from trying to load every row of data from my data source. Instead, I externally (i.e., in my own custom code) sort the data and put the sorted results into a DataTable that I then feed to the grid control.
What you mean by "external" settings?
You're right, it doesn't make sense to clear the columns when I'm sorting. I did it because I was reusing the code that initially populates a grid. But when I redesign my code so that I do not destroy my columns when I'm sorting an already loaded grid, then I do get the Sort Indicator to work the way I want it.
I can understand clearing the rows from the UltraDataSource, but why clear the columns? That doesn't make sense. This is probably what's causing the problem. You are destroying the column in the data source, thus destroying it in the grid. So the SortIndicator property is getting lost, since the column is no longer there.
Also, I don't think this matter to the problem, but you should probably be using Before/AfterSortChange rather than MouseDown.
Nope, I'm still missing something.
I HeaderClickAction to ExternalSortSingle. In my MouseDown event handler, I check to see if user clicked on a Column Header element. If so, I "sort".
My implementation uses a virtual grid, so to do a sort, I:
Next, still within the MouseDown event handler, I examine the SortIndicator of the clicked column. It's "none", so I set it to "ascending."
However, this does not draw the sort indicator icon (triangle) on my grid's column header. If I click the same column's header again, then as soon as I enter the Mouse Down event handler, I examine the selected element to find that its SortIndicator is "none".
Any suggestions?