大家给我看下我的MSFlexGrid排序函数,作用是左键点击列标题时,进行升序或者降序排列MSFlexGrid中的数据,在使用时发现对于以下这样的数据
12-001
12-002
12-003
12-004
12-005
12-006
12-007
12-008
就不能排序了。请高手们帮忙看下完善这个函数啦
Option ExplicitPublic Const STR_SORT_ASC = "△"
Public Const STR_SORT_DESC = "▽"'//排序函数
Public Sub Sort(sgrd As MSFlexGrid, y As Single)
With sgrd
If y >= .RowPos(0) And y < .RowPos(1) Then
If .Tag <> "" Then
If .Tag <> .Col Then
.TextMatrix(0, .Tag) = Left(.TextMatrix(0, .Tag), Len(.TextMatrix(0, .Tag)) - 1)
End If
End If
If Right(.TextMatrix(0, .Col), 1) = STR_SORT_ASC Then
.Sort = flexSortGenericAscending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_ASC, STR_SORT_DESC)
ElseIf Right(.TextMatrix(0, .Col), 1) = STR_SORT_DESC Then
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_DESC, STR_SORT_ASC)
Else
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = .TextMatrix(0, .Col) & STR_SORT_ASC
End If
.Tag = .Col
End If
End With
End Sub
12-001
12-002
12-003
12-004
12-005
12-006
12-007
12-008
就不能排序了。请高手们帮忙看下完善这个函数啦
Option ExplicitPublic Const STR_SORT_ASC = "△"
Public Const STR_SORT_DESC = "▽"'//排序函数
Public Sub Sort(sgrd As MSFlexGrid, y As Single)
With sgrd
If y >= .RowPos(0) And y < .RowPos(1) Then
If .Tag <> "" Then
If .Tag <> .Col Then
.TextMatrix(0, .Tag) = Left(.TextMatrix(0, .Tag), Len(.TextMatrix(0, .Tag)) - 1)
End If
End If
If Right(.TextMatrix(0, .Col), 1) = STR_SORT_ASC Then
.Sort = flexSortGenericAscending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_ASC, STR_SORT_DESC)
ElseIf Right(.TextMatrix(0, .Col), 1) = STR_SORT_DESC Then
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_DESC, STR_SORT_ASC)
Else
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = .TextMatrix(0, .Col) & STR_SORT_ASC
End If
.Tag = .Col
End If
End With
End Sub
With Flex
.MousePointer = vbHourglass
If .MouseRow = 0 Then
.Col = .MouseCol
If bSortOrder = False Then
.Sort = flexSortGenericDescending
bSortOrder = True
Else
.Sort = flexSortGenericAscending
bSortOrder = False
End If
.Col = 1
.ColSel = .Cols - 1
End If
.MousePointer = vbDefault
End With
End Sub应该可以满足巴
12-001
12-002
12-003
12-004
12-005
12-006
12-007
12-008
不能排序
我也是按
.Sort = flexSortGenericAscending
.Sort = flexSortGenericDescending
来处理,对上述数据不起作用
.Sort = 5 '字符串排升序
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_ASC, STR_SORT_DESC)
ElseIf Right(.TextMatrix(0, .Col), 1) = STR_SORT_DESC Then
.Sort = 6 '字符串排倒序
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_DESC, STR_SORT_ASC)
Else
.Sort = 6
.TextMatrix(0, .Col) = .TextMatrix(0, .Col) & STR_SORT_ASC
End If