Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort an UltraGrid by multiple columns programmatically?

Say we have an UltraGrid. How can I sort it programmatically first by column A, then B, then C.

Thanks!

like image 871
Andrei Avatar asked Feb 08 '11 20:02

Andrei


People also ask

How do I sort UltraGrid?

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.

What is a multi column sort?

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).


2 Answers

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

like image 132
theChrisKent Avatar answered Sep 23 '22 08:09

theChrisKent


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

like image 25
Dominik Ras Avatar answered Sep 25 '22 08:09

Dominik Ras