下面的示例使用 Sort 和 TextMatrix 属性。它根据一个 ComboBox 控件的值执行一个 MSHFlexGrid 排序。要使用该示例,在窗体中放置一个 MSHFlexGrid 控件和一个 ComboBox 控件。把下面的代码粘贴到 Declarations 节,然后按 F5 键。
注意 如果正在使用 MSFlexGrid,用“MSFlexGrid1”代替“MSHFlexGrid1”。
Private Sub Combo1_Click()
' 根据排序方法选择列。
Select Case Combo1.ListIndex
Case 0 To 2
MSHFlexGrid1.Col =1
Case 3 To 4
MSHFlexGrid1.Col =2
Case 4 To 8
MSHFlexGrid1.Col =1
End Select
' 根据 Combo1.ListIndex 排序。
MSHFlexGrid1.Sort =Combo1.ListIndex
End Sub
Private Sub Form_Load()
Dim i As Integer
vba排序函数sort用法' 用随机数据填充 MSHFlexGrid。
MSHFlexGrid1.Cols =3 ' 创建三列。
For i =1 To 11 ' 添加十项。
MSHFlexGrid1.AddItem ""
MSHFlexGrid1.Col =2
MSHFlexGrid1.TextMatrix(i, 1) =SomeName(i)
MSHFlexGrid1.TextMatrix(i, 2) =Rnd()
Next i
' 用排序选择填充 combo 框。
With Combo1
.AddItem "flexSortNone" ' 0
.AddItem "flexSortGenericAscending" '1
.AddItem "flexSortGenericDescending" '2
.AddItem "flexSortNumericAscending" '3
.AddItem "flexSortNumericDescending" '4
.AddItem "flexSortStringNoCaseAsending" '5
.AddItem "flexSortNoCaseDescending" '6
.AddItem "flexSortStringAscending" '7
.AddItem "flexSortStringDescending" '8
.ListIndex =0
End With
End Sub
Private Function SomeName(i As Integer) As String
Select Case i
Case 1
SomeName ="Ann"
Case 2
SomeName ="Glenn"
Case 3
SomeName ="Sid"
Case 4
SomeName ="Anton"
Case 5
SomeName ="Hoagie"
Case 6
SomeName ="Traut 'Trane"
Case 7
SomeName ="MereD Wah"
Case 8
SomeName ="Kemp"
Case 9
SomeName ="Sandy"
Case 10
SomeName ="Lien"
Case 11
SomeName ="Randy"
End Select
End Function
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论