标题:如何实现click msflexgrid的column的caption,msflexgrid中的内容自动按ca ...
只看楼主
vbtom
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-9-5
 问题点数:0 回复次数:2 
如何实现click msflexgrid的column的caption,msflexgrid中的内容自动按caption排序?
如何实现click msflexgrid的column的caption,msflexgrid中的内容自动按caption排序?Thanks!
搜索更多相关主题的帖子: caption column msflexgrid click 自动 
2007-12-18 17:11
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
先添加MSFlexGrid控件,方法:菜单->工程->部件->Microsoft FlexGrid Control 6.0(后面为版本号),代码如下:

Option Explicit
Private Const STR_SORT_ASC = "△"
Private Const STR_SORT_DESC = "▽"
Private Sub Form_Load()
    Dim i As Long
   
    '添加一些试验数据
    With MSFlexGrid1
        .Rows = 51
        .Cols = 5
        For i = 0 To 50
            .TextMatrix(i, 0) = ("Col" & i)
            .TextMatrix(i, 1) = ("Col" & i)
            .TextMatrix(i, 2) = ("Col" & i)
            .TextMatrix(i, 3) = ("Col" & i)
            .TextMatrix(i, 4) = ("Col" & i)
        Next
    End With
End Sub
'排序函数
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
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Sort MSFlexGrid1, y
End Sub

我的msn: myfend@
2007-12-18 17:24
vbtom
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-9-5
得分:0 
多谢版主!
2007-12-19 08:38



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-193182-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.961619 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved