Hi,
I am trying to sort groupby Rows base on the grid row index. The sorting that is shown on Picture1 is exactly what I want. It can be done using IComparator by comparing the row index. However, once I add another sorted column under that group, the sort has changed. Here are my questions:
1. Is there a way I can fix the GroupbyRow order (in my case, PIcture 1 attachment as is) no matter how I change the rest of the grouping?
2. Is there a way I can GroupBy base on the row index?
I do not know if I am asking the right questions but I just want my "Scenario" column to have specific GroupBy order. I do not want to see any other grouping interrupting that order. Any idea?
Thanks!
I'm afraid I am still not really clear on what you want here. It looks like the first picture has the rows in ascending order and the second has them in descending order. If simply adding a second grouping is causing that, then my best guess is that something is wrong with your GroupByComparer.
Your statement that you want the groups sorted by the index doesn't really make any sense. What index are you referring to? The index of the rows before they were sorted? You can't do that, because first of all, the index is lost once the rows are grouped, since they are now in a new order. You can't sort rows by something that will change as the sort is processed. Also, what if there is more than one row in a group? Which row's index would you use?
It seems like what you want to do is always keep the groups sorted in ascending order. If that's all you want, then you don't need a GroupByComparer at all. All you have to do is stop the user from sorting the rows in descending order. The way to do that would be to handle the BeforeSortChange event and trap for changes to the sort order of the column that is being grouped, and if the order is being changed to Descending, cancel the event by setting e.Cancel to true.
If I am wrong about what you are trying to do here, and for some reason you do need a GroupByComparer, then you need to be aware of the fact that the grid will reverse the sign of the results of the Compare method when sorting Descending. The Comparer is, in theory, supposed to be unaware of the direction of the sorting. For example 1 is always less than 2, as far as the Comparer is concerned. But if you sort the grid descending, the grid has to reverse the order. So you might need to check if the column is being sorted descending, and if so, reverse the value you return from your comparer.
If you refer to the attached (Picture2.jpg), once I group an addition column, all the orders are sorted which I do not want to see. Do you understand what I am trying to say? Sorry for the confusion.
As I mentioned above, I did implement GroupByComparer. The attached attachment shows the correct order I would like to see.
I'm afraid I do not understand what you are trying to do and there is no picture attached to your post.
If you want to sort the GroupByRows in the grid in a different order than the grouped column is sorted, then you can use the GroupByComparer property on the column. I've discussed this on these forums many times, so if you search for GroupByComparer, you will find a lot of info on this and how it works.