View Single Post
 
Old 11-07-2003, 10:24 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,164
Default Autoresize of columns in MSHFlexGrid with multiple bands

Code:
Public Function FG_AutosizeCols(myGrid As MSHFlexGrid, _ 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 .Redraw = False If bCheckFont Then lCurRow = .Row lCurCol = .Col End If If lFirstCol = -1 Then lFirstCol = 0 ' Special for MSHFlexGrid with multiple bands If lLastCol = -1 Then lLastCol = 0 For i = 0 To .Bands - 1 lLastCol = lLastCol + .Cols(i) Next i lLastCol = lLastCol - 1 End If 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("WW") Next lCol If bCheckFont Then .Row = lCurRow .Col = lCurCol End If .Redraw = True End With If bCheckFont Then ' restore the forms font settings Me.FontBold = bFontBold Me.FontName = sFontName Me.FontSize = dFontSize End If End Function
Reply With Quote