大家给我看下我的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

解决方案 »

  1.   

    不好意思,我用的是VSFLexGrid8.0,这个第三方控件有一个ExplorerBar 属性,将其设为flexExSortShow就可以自动排序。
      

  2.   

    VSFLexGrid8.0可以达到你想要的效果,只需要将上述属性设一下,就OK了
      

  3.   

    Public Sub SortMsflex(ByVal Flex As MSFlexGrid)
            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应该可以满足巴
      

  4.   

    没有用 和我的一样 惟独对
    12-001
    12-002
    12-003
    12-004
    12-005
    12-006
    12-007
    12-008
    不能排序
    我也是按
    .Sort = flexSortGenericAscending
    .Sort = flexSortGenericDescending
    来处理,对上述数据不起作用
      

  5.   

    If Right(.TextMatrix(0, .Col), 1) = STR_SORT_ASC Then
     .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