MSHFlexGrid多列排序

xelement發表於2007-10-17
一萬行,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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章