Public Function FG_AutosizeRows(myGrid As MSFlexGrid, _
Optional ByVal lFirstRow As Long = -1, _
Optional ByVal lLastRow As Long = -1, _
Optional bCheckFont As Boolean = False)
' This will only work for Cells with a Chr(13)
' To have it working with WordWrap enabled
' you need some other routine
' Which has been added too
Dim lCol As Long, lRow As Long, lCurCol As Long, lCurRow As Long
Dim lCellHeight As Long, lRowHeight As Long
Dim bFontBold As Boolean
Dim dFontSize As Double
Dim sFontName As String
If bCheckFont Then
' save the forms font settings
bFontBold = Me.FontBold
sFontName = Me.FontName
dFontSize = Me.FontSize
End If
With myGrid
If bCheckFont Then
lCurCol = .Col
lCurRow = .Row
End If
If lFirstRow = -1 Then lFirstRow = 0
If lLastRow = -1 Then lLastRow = .Rows - 1
For lRow = lFirstRow To lLastRow
lRowHeight = 0
If bCheckFont Then .Row = lRow
For lCol = 0 To .Cols - 1
If bCheckFont Then
.Col = lCol
Me.FontBold = .CellFontBold
Me.FontName = .CellFontName
Me.FontSize = .CellFontSize
End If
lCellHeight = Me.TextHeight(.TextMatrix(lRow, lCol))
If lCellHeight > lRowHeight Then lRowHeight = lCellHeight
Next lCol
.RowHeight(lRow) = lRowHeight + Me.TextHeight("Wg") / 5
Next lRow
If bCheckFont Then
.Row = lCurRow
.Col = lCurCol
End If
End With
If bCheckFont Then
' restore the forms font settings
Me.FontBold = bFontBold
Me.FontName = sFontName
Me.FontSize = dFontSize
End If
End Function
Public Function FG_AutosizeCols(myGrid As MSFlexGrid, _
Optional ByVal lFirstCol As Long = -1, _
Optional ByVal lLastCol As Long = -1, _
Optional bCheckFont As Boolean = False)
Dim lCol As Long, lRow As Long, lCurCol As Long, lCurRow As Long
Dim lCellWidth As Long, lColWidth As Long
Dim bFontBold As Boolean
Dim dFontSize As Double
Dim sFontName As String
If bCheckFont Then
' save the forms font settings
bFontBold = Me.FontBold
sFontName = Me.FontName
dFontSize = Me.FontSize
End If
With myGrid
If bCheckFont Then
lCurRow = .Row
lCurCol = .Col
End If
If lFirstCol = -1 Then lFirstCol = 0
If lLastCol = -1 Then lLastCol = .Cols - 1
For lCol = lFirstCol To lLastCol
lColWidth = 0
If bCheckFont Then .Col = lCol
For lRow = 0 To .Rows - 1
If bCheckFont Then
.Row = lRow
Me.FontBold = .CellFontBold
Me.FontName = .CellFontName
Me.FontSize = .CellFontSize
End If
lCellWidth = Me.TextWidth(.TextMatrix(lRow, lCol))
If lCellWidth > lColWidth Then lColWidth = lCellWidth
Next lRow
.ColWidth(lCol) = lColWidth + Me.TextWidth("W")
Next lCol
If bCheckFont Then
.Row = lCurRow
.Col = lCurCol
End If
End With
If bCheckFont Then
' restore the forms font settings
Me.FontBold = bFontBold
Me.FontName = sFontName
Me.FontSize = dFontSize
End If