Hi Team,
I am currently using a UltraGrid which bind to UltraDataSource. I want to apply sort function on the grid.
1. I tried grid.SortedColumns.Add(XXX). This applied the sort on Grid. However, I found out this won't effect the data on UltraDataSouce which somehow I need to sorted as well.
2. Then I tried to sort on the ultraDataSource. I sorted the tag of rows as well. However, it doesn't apply any sort on the grid. Am I missing anything? Do I need to sort on the UltraDataSource.Rows rather than Tag? How can I get the businees object behind and sort on the them?
List<Row> rows_= mainUltraDataSource.Rows.Tag as List<Row>;
rows_.Sort(XXX)
Thanks,
Xin
Hi Mike,
The Sort external choices is working perfectly. However, I still didn't find a way to sort on UltraDataSource.Rows. Just as you mentioned before, change the order or UltraDataSource.Rows.Tag doesn't really change the UltraDataSource.Rows. Do you have any example to achieve this?
Many Thanks,
Do your users need the ability to select column?
If so, then you won't be able to use the built-in sort indicators on the columns.You cannot have both colun selection and sorting enabled at the same time.
If you do not need column selection, then set the HeaderClickAction to one of the External choices. Once you do that, setting the SortIndicator on the column will only display the sort indicator in the column header without sorting the grid data.
A SortComparer will not do anything unless you want the grid to do the sorting for you, which I don't think you want.
Thanks Mike,
I will try to sort on each child rows see if it work. I haven another question though. I am not sure HeaderClickAction to sort my grid. HeaderClick will just select the column. I am using a right click context menu to allo user choose which kind of sort they want to apply. However, after sort the data source, I didn't see any indicator there. Is there a way to show the indicator? If I am using column.SortIndicator = Aceding, I will sort the grid but not the way I wanted(I put the logic in my Row Comparer class). It means I need to set the SortComparer for that column as well...Is that the right way to do?
Hi,
I'm afraid it's very hard to offer you advice on this, since I really don't understand what you are doing with the Tag.
The child rows are stored in different collections - there's no one collection that contains all of the rows, so it seems like whatever you are doing, you would have to walk over the child rows and sort each collection individually.
If you need to sort your data source and keep it in synch with the grid, then you might be better off using a DataSource that has sorting functionality, like a DataSet. You could set the HeaderClickAction on the grid to one of the "External" settings. This makes it so that the grid will display the sort indicators on the column headers and respond to clicks, but the grid will not do any actually sorting. It's left to you.
So then you have handle the BeforeSortChanged event, sort your data, and refresh the grid display to match the new sort order of the data.
Thanks for your reply.
The reason why I need to do sort on data srouce level is due to we get data/insert new data all on data source rather than from the real grid.
I do place an object into UltraDataSource.Rows.Tag which supports sorting. Now, after I refresh my grid, I do see the sorting applied. However, it just apply to the first band. It doesn't apply to the child band even if I've already sort the child rows of the parent object Row. Besides, it doesn't change the child band sturcture either. For example, before sorting, the row structur is like below:
Row 1 -> Child Row 1, Child Row2.
Row2
After sorting, it's like below:
Row 2 -> Child Row 1, Child Row2.
Row 1
Could you please advice?