18

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

Thanks!

Andrei
  • 4,122
  • 3
  • 22
  • 24

2 Answers2

29

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

Christopher Berman
  • 719
  • 1
  • 5
  • 21
theChrisKent
  • 15,029
  • 3
  • 61
  • 62
  • @Xander yeah, they seem to have switched their site around and not added any redirects. It's not the same one referenced above, but it looks like they do have an article on sorting that can be found here:http://www.infragistics.com/help/topic/ED043A4B-031A-48A8-8A20-9BEA498DE71A However, the solution posted is still valid. – theChrisKent Aug 21 '12 at 12:52
  • Thanks, simple and helpful solution – Rice Dec 16 '16 at 16:49
2

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

Dominik Ras
  • 511
  • 5
  • 6