'**************************************
' Name: Auto resize flexgrid column widt
' hs
' Description:Automatically resize the c
' olumns in any flex grid to give a nice,
' professional appearance.
'
'
'Public sub automatically resizes MS Flex Grid columns to match the width of the text, no matter the size of the grid or the 'number of columns.
' Reads first n number of rows of data, and adjusts column size to match the widest cell of text. Will even expand columns 'proportionately if they aren't wide enough to fill out the entire width of the grid. Configurable constraints allow you to 'designate
' 1) Any flex grid to resize
' 2) Maximum column width
' 3) the maximum number of rows in depth to look for the widest cell of text.
' By: Jonathan W. Lartigue
'
'
' Inputs:msFG (MSFlexGrid) = The name of
' the flex grid to resize .... MaxRowsToPa
' rse (integer) = The maximum number of ro
' ws (depth) of the table to scan for cell
' width (e.g. 50) .... MaxColWidth (Intege
' r) = The maximum width of any given cell
' in twips (e.g. 5000)
'
' Returns:None
'
'Assumes:Simply drop this public sub int
' o your form or module and access it from
' anywhere in your program to automaticall
' y resize any flex grid.
'
'Side Effects:None
'This code is copyrighted and has limite
' d warranties.
'Please see http://www.Planet-Source-Cod
' e.com/xq/ASP/txtCodeId.8547/lngWId.1/qx/
' vb/scripts/ShowCode.htm
'for details.
'**************************************
Public Sub AutosizeGridColumns(ByRef msFG As MSFlexGrid, ByVal MaxRowsToParse As Integer, ByVal MaxColWidth As Integer)
Dim I, J As Integer
Dim txtString As String
Dim intTempWidth, BiggestWidth As Integer
Dim intRows As Integer
Const intPadding = 150
With msFG
For I = 0 To .Cols - 1
' Loops through every column
.Col = I
' Set the active colunm
intRows = .Rows
' Set the number of rows
If intRows > MaxRowsToParse Then intRows = MaxRowsToParse
' If there are more rows of data, reset
' intRows to the MaxRowsToParse constant
'
intBiggestWidth = 0
' Reset some values to 0
For J = 0 To intRows - 1
' check up to MaxRowsToParse # of rows a
' nd obtain
' the greatest width of the cell content
' s
.Row = J
txtString = .Text
intTempWidth = TextWidth(txtString) + intPadding
' The intPadding constant compensates fo
' r text insets
' You can adjust this value above as des
' ired.
If intTempWidth > intBiggestWidth Then intBiggestWidth = intTempWidth
' Reset intBiggestWidth to the intMaxCol
' Width value if necessary
Next J
.ColWidth(I) = intBiggestWidth
Next I
' Now check to see if the columns aren't
' as wide as the grid itself.
' If not, determine the difference and e
' xpand each column proportionately
' to fill the grid
intTempWidth = 0
For I = 0 To .Cols - 1
intTempWidth = intTempWidth + .ColWidth(I)
' Add up the width of all the columns
Next I
If intTempWidth < msFG.Width Then
' Compate the width of the columns to th
' e width of the grid control
' and if necessary expand the columns.
intTempWidth = Fix((msFG.Width - intTempWidth) / .Cols)
' Determine the amount od width expansio
' n needed by each column
For I = 0 To .Cols - 1
.ColWidth(I) = .ColWidth(I) + intTempWidth
' add the necessary width to each column
'
Next I
End If
End With
End Sub
|
讓我們程式搜尋結果更加完美 如果您覺得該文件有幫助到您,煩請按下我如果您覺得該文件是一個一無是處的文件,也煩請按下我 |
|
該文件您看起來是亂碼嗎?您可以切換編碼方式試試看!ISO-8859-1 | latin1 | euc-kr | euc-jp | CP936 | CP950 | UTF-8 | GB2312 | BIG5 |
|