如何通过编程方式对多列UltraGrid进行排序?

时间:2011-02-08 20:18:08

标签: c# .net infragistics ultragrid

假设我们有一个UltraGrid。 我如何首先按编程方式对其进行排序,然后是B,然后是B,然后是C.

谢谢!

2 个答案:

答案 0 :(得分:23)

此处的文档: http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridBand~SortedColumns.html

您只需设置排序指标(顺序很重要),代码取自上面的链接

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

有关第二种方法的更多信息,请访问: http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v8.2~Infragistics.Win.UltraWinGrid.SortedColumnsCollection~Add.html

答案 1 :(得分:2)

如果您还想通过ContactName自动分组,可以为您执行此操作:

band.SortedColumns.Add( "ContactName", false, true);

注意使用true作为最后一个参数