Hi. My app has separate columns for date, time and other data. I need to sort the grid based first on the date, and then by the time column. I'm using the following code to sort by both columns but it doesn't work:
band.Columns[timeColumnKey].SortIndicator = SortIndicator.Descending;
band.Columns[dateColumnKey].SortIndicator = SortIndicator.Descending;
Does anyone know how I can sort by the contents of two columns?
I'm using version 10.2. Thanks.
If your grid is bound and has columns at design-time, the easiest thing to do is simply click on the column headers in the designer just as you would do at run-time.To sort by more than one column, you click on the first column header then hold the shift key while clicking on another column header.
Another option would be to use the property grid and go to grid.DisplayLayout.Bands[X].Columns[X].SortIndicator
ok, I see that I can set that at runtime, but I'm looking for it in the designer. Is there some reason it's not available there?
UltraGridBand
band = myGrid.DisplayLayout.Bands[0];
band.SortedColumns.Add(....);
Hope that helps.
The bands in my ultragrid do not have a SortedColumns collection. Am I missing something? I'm using 2010.3.
gregstoops said:1. Once I create the sorted columns collection, do I have to execute a command to sort on the collection? Or, does the grid know to keep things sorted that way for some period of time?
Adding a column into the SortedColumns collection of the band will cause the grid to immediately update the display so that the data is sorted as you specified.
gregstoops said:2. If the user resorts the grid by clicking on a column header, can I force the columns to be sorted again (by the sorted columns collection) in the future? Or, do I have to re-create the sorted columns collection first?
You don't create the collection, the SortedColumn collection is a property which is exposed by the band. Anyway, if you want to change the sorting you could do it in code any time you want. For example, you could trap the BeforeSortChanged event of the grid and examine the SortedColumns which are passed into the event to see what the user chose to sort by and then change the sorting in whatever way you like.