datagrid如何自动调整列宽适应控件大小?
1个回答
展开全部
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 IfNext
以上是自动调整何时宽度的函数,下面为使用方法: AdjustColWidth frmMain, MSFlexGrid1 '调整Grid各列列宽为最合适的宽度 以上函数是用于MSFlexGrid的,DataGrid差不了多少,把它改改就好了比如把MSFlexGrid1.ColWidth(i)改为DataGrid1.Columns(i).Width
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询