分享

两个MSFlexGrid的函数 点击表头排序函数以及依据内容自动调整列宽为最合适的宽度

 网络摘记 2014-10-17
Public Const STR_SORT_ASC = "△"
Public Const STR_SORT_DESC = "▽"

'//排序函数
Public Sub Sort(sgrd As MSHFlexGrid, 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


'//自动调整Grid各列列宽为最合适的宽度
Public Sub AdjustColWidth(frmCur As Form, gridCur As Object, Optional bNullRow As Boolean = True, Optional dblIncWidth As Double = 0)
'--------------------------------------------------------------------
'功能:
'               自动调整Grid各列列宽为最合适的宽度
'参数:
'               [frmCur]......................当前工作窗体
'               [gridCur].....................当前要调整的Grid
'--------------------------------------------------------------------
Dim i, j As Integer
Dim dblWidth As Double

With gridCur
   For i = 0 To .Cols - 1
      dblWidth = 0
      If .ColWidth(i) <> 0 Then
         For j = 0 To .Rows - 1
            If frmCur.TextWidth(.TextMatrix(j, i)) > dblWidth Then
               dblWidth = frmCur.TextWidth(.TextMatrix(j, i))
            End If
         Next
'        .ColWidth(i) = dblWidth + dblIncWidth + 100
      End If
   Next
End With

End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多