Say we have an UltraGrid. How can I sort it programmatically first by column A, then B, then C.
Thanks!
The UltraGrid maintains sort and group-by columns in the SortedColumns collection. You can use this property to sort and group rows by a column in code. To do that add the column you want to sort or group rows by to the the SortedColumns collection using the SortedColumnsCollection. Add method.
Multicolumn sorting allows you to sort the fields one after the other. For example, if a user has three different fields rendered in the pivot grid, then it is possible to sort like: OrderBy(field1).
Documentation here: http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridBand~SortedColumns.html
You can just set the sort indicator (order is important), code taken from above link:
UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0];
// Sort the rows by Country and City fields. Notice the order in which these columns
// are set. We want to sort by Country and then sort by City and in order to do that
// we have to set the SortIndicator property in the right order.
band.Columns["Country"].SortIndicator = SortIndicator.Ascending;
band.Columns["City"].SortIndicator = SortIndicator.Ascending;
// You can also sort (as well as group rows by) columns by using SortedColumns
// property off the band.
band.SortedColumns.Add( "ContactName", false, false );
More information on the second method can be found here: http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v8.2~Infragistics.Win.UltraWinGrid.SortedColumnsCollection~Add.html
If you also wanted to automatically group by ContactName this may do it for you:
band.SortedColumns.Add( "ContactName", false, true);
Notice usage of true as the last parameter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With