找回密码
 立即注册

QQ登录

只需一步,快速开始

chenf1980

论坛元老

41

主题

147

帖子

9349

积分

论坛元老

积分
9349

活字格认证

chenf1980
论坛元老   /  发表于:2011-7-20 18:07  /   查看:9860  /  回复:12
SortMode里面有 AutoMatic 与 Programmatic,AutoMatic是自动排序的,但是我想实现,点这个Head的时候,按照另外一个字段来排序,应该是通过Programmatic来实现的吧?请问应该在哪里写代码呢?

12 个回复

倒序浏览
barrylei
中级会员   /  发表于:2011-7-20 21:18:00
沙发
1. 把你所要排序的字段绑定到一个Row上的Cell,为了描述方便,我叫这个Cell 为TextBoxCelln
2. 把TextBoxCelln在Visible设置成False,为了不让EndUser看见它。
3. 最好把TextBoxCelln在模板上放在你的某一个可见Cell的背后。
4. 然后把你要点的那个Header的SortCellName设置到TextBoxCelln,SortMode设置成Automatic 就可以了。
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-7-21 08:49:00
板凳
忘记说了,我的MultiRow是5.0版本,没有SortCellName这个属性
回复 使用道具 举报
barrylei
中级会员   /  发表于:2011-7-21 09:00:00
地板
Sorry.
在5.0里,先看一下TextBoxCelln的Index是多少,然后设置SortCellIndex到它。
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-7-21 09:54:00
5#
恩,如果是复数的情况下呢?比如需要sort的是,CellIndex1,CellIndex2,可以用逗号来区分吗?
回复 使用道具 举报
barrylei
中级会员   /  发表于:2011-7-21 10:43:00
6#
不行,我们不支持用逗号来做多个列的sort。如果是这个需求的话,那请按照下面的步骤做,
1. 设置headercell的SortOrder到Programming
2. 然后在CellClick事件里面写下面的代码。使用的是Sort方法,里面可以传多个SortItem,每个SortItem对应一列,然后自己去设置ColumnHeaderCell的SortGlyphDirection 来显示Sort的上下箭头。

  1.        int i = 1;
  2.         private void gcMultiRow1_CellClick(object sender, GrapeCity.Win.MultiRow.CellEventArgs e)
  3.         {
  4.             if (e.CellName == "headercell")
  5.             {
  6.                 SortOrder sororder = (SortOrder)(i % 2);
  7.                 this.gcMultiRow1.Sort(new SortItem[] { new SortItem("cell1") { SortOrder = sororder }, new SortItem("cell2") { SortOrder = sororder } });
  8.                 (this.gcMultiRow1.ColumnHeaders[0].Cells["headercell"] as ColumnHeaderCell).SortGlyphDirection = sororder;
  9.             }
  10.         }
复制代码
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-7-21 11:28:00
7#
不好意思,能换成VB语法吗
回复 使用道具 举报
barrylei
中级会员   /  发表于:2011-7-21 12:13:00
8#

  1. Imports GrapeCity.Win.MultiRow
  2. Public Class Form1
  3.     Dim i As Integer = 1
  4.     Private Sub GcMultiRow1_CellClick(ByVal sender As Object, ByVal e As GrapeCity.Win.MultiRow.CellEventArgs) Handles GcMultiRow1.CellClick
  5.         If (e.CellName = "headercell1") Then
  6.             Dim sortorder As SortOrder = i Mod 2 + 1

  7.             Dim sortitem1 As New SortItem
  8.             sortitem1.CellName = "Cell1"
  9.             sortitem1.SortOrder = sortorder

  10.             Dim sortitem2 As New SortItem
  11.             sortitem2.CellName = "Cell2"
  12.             sortitem2.SortOrder = sortorder

  13.             Dim mySort() As SortItem = {sortitem1, sortitem2}
  14.             Me.GcMultiRow1.Sort(mySort)

  15.             TryCast(Me.GcMultiRow1.ColumnHeaders(0).Cells("headercell1"), ColumnHeaderCell).SortGlyphDirection = sortorder

  16.             i = i + 1

  17.         End If
  18.     End Sub
  19. End Class

复制代码
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-7-21 13:57:00
9#
版主,你确定能通过吗?
我这边一执行就出错啊。
到这一行出错:  Me.GcMultiRow1.Sort(mySort)


提示说指定的cellIndex = -1或者cellname = '' 所包含的单元格不存在。
回复 使用道具 举报
robert
金牌服务用户   /  发表于:2011-7-21 14:09:00
10#
sortitem1.CellName = "Cell1"
sortitem2.CellName = "Cell2"

试下把这两句中的“Cell1”和“Cell2” 换成你想要排序的Cell的名字,看看行不行。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部