Hi,
Is there any way of changing the direction that a column initialy sorts in? Currently it sems that the UltraGrid will sort in Ascending order first, but we would prefer this to be descending.
I have tried changing the SortIndicator property of all columns that are not in the current sorted set in the BeforeSortChange event. However when I do this I recieve an Argument exception saying its its not possible to modify the collection in this event.
Thanks
Chris
Hi Mike, thank you for look into it. We could like to have multi column sort. I use a comparer class for my image columns to change sort value to make it work.
Thanks,
Crystal.
Hi Crystal,
I tried out my sample code above and I do indeed get some weird results when I click on a second column header. It looks like my SortColumnDescending code was not quite complete. I am adding the new sorted column, but I never cleared the old one. So the grid ends up sorting both columns descending, but since the first sorted column contains unique values, the second sort doesn't do anything.
If you only want a single-column sort, then you can do this:
private void SortColumnDescending(UltraGridColumn column) { // Disable the BeforeSortChange event to avoid recursion. this.ultraGrid1.EventManager.SetEnabled(GridEventIds.BeforeSortChange, false); try { // Sort the specific column descending. column.Band.SortedColumns.Clear(); column.Band.SortedColumns.Add(column, true); } finally { //Re-enabled the BeforeSortChange event. this.ultraGrid1.EventManager.SetEnabled(GridEventIds.BeforeSortChange, true); } }
All I did was add the call to SortedColumns.Clear before adding the new column.
Hi Mike, we have similar requirement that needs to sort some image columns descending when first click on the column header. Your approach works first time click on a column. But when I click on another column header, that column wasn't sorted by descending, however, SortColumnDescending method was called though.
Thank you both for your help.
I have found the mean of doing it too. My solution is not so elegant as Mike's one, but it works.
See attached small project.