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
说明:以上模块实现MSHFlexGrid的单元格根据内容自动调整宽度.
调用方式
call AdjustColWidth(Form_Name,MSHFlexGrid_Name)
放在公共模块中,第一个自动调整宽度的过程在调用的时候需要注意窗体名称和窗体中的MSHFlexGrid控件的名称.别在A窗体调用出B窗体的控件…
联系客服