如何通过编程实现UltraGrid多列排序?

18

假设我们有一个UltraGrid。 如何通过编程先按列A,然后按列B,最后按列C进行排序。

谢谢!

2个回答

29

文档在这里: 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


@Xander 是的,他们似乎已经改变了他们的网站,并没有添加任何重定向。这不是上面提到的那个网站,但看起来他们确实有一篇关于排序的文章,可以在这里找到:http://www.infragistics.com/help/topic/ED043A4B-031A-48A8-8A20-9BEA498DE71A 然而,发布的解决方案仍然有效。 - theChrisKent
谢谢,简单而有用的解决方案。 - Rice

2
如果您想自动按ContactName分组,可以尝试以下方法:
band.SortedColumns.Add( "ContactName", false, true);

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接