ITPub博客

首页 > 应用开发 > IT综合 > MSHFlexGrid多列排序

MSHFlexGrid多列排序

原创 IT综合 作者:xelement 时间:2007-10-17 21:27:46 0 删除 编辑
一万行,3秒搞定
Const ASC As Long = 1
Const DESC As Long = -1
Private SortType As Long

Private Sub Command1_Click()
SortType = ASC
Debug.Print Now
MSHFlexGrid1.Sort = 9
Debug.Print Now
End Sub

Private Sub Command2_Click()
SortType = DESC
MSHFlexGrid1.Sort = 9
End Sub

Private Sub Form_Load()
Randomize
With MSHFlexGrid1
For i = 1 To .Rows - 1
.TextMatrix(i, 3) = CStr(i)
.TextMatrix(i, 1) = Format(Rnd, "0.0")
Next
End With
End Sub

Private Sub MSHFlexGrid1_Compare(ByVal Row1 As Long, ByVal Row2 As Long, Cmp As Integer)
Dim x1 As Double, x2 As Double, n1 As Long, n2 As Long

x1 = CDbl(MSHFlexGrid1.TextMatrix(Row1, 1))
x2 = CDbl(MSHFlexGrid1.TextMatrix(Row2, 1))
If x1 < x2 Then
Cmp = -1
ElseIf x1 > x2 Then
Cmp = 1
Else "第一列相等的情况下,按第三列排序
n1 = CLng(MSHFlexGrid1.TextMatrix(Row1, 3))
n2 = CLng(MSHFlexGrid1.TextMatrix(Row2, 3))
If n1 < n2 Then
Cmp = -1
ElseIf n1 > n2 Then
Cmp = 1
Else
Cmp = 0
End If
End If

Cmp = Cmp * SortType
End Sub[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/778857/viewspace-977300/,如需转载,请注明出处,否则将追究法律责任。

下一篇: table-style
请登录后发表评论 登录
全部评论

注册时间:2007-12-11

  • 博文量
    11
  • 访问量
    12069