|
-
Mar 28th, 2000, 12:50 AM
#1
Thread Starter
Addicted Member
How do you have vb automatically size a msflexgrid to the longest field in the record extracted from the database?
does anyone know?
-
Mar 28th, 2000, 04:14 AM
#2
Here is a Generic routine I've put together a while back:
Code:
Public Sub ResizeGrid(pGrid As MSFlexGrid, pForm As Form)
Dim intRow As Integer
Dim intCol As Integer
With pGrid
For intCol = 0 To .Cols - 1
For intRow = 0 To .Rows - 1
If .ColWidth(intCol) < pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100 Then
.ColWidth(intCol) = pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100
End If
Next
Next
End With
End Sub
Then just call this routine like this:
ResizeGrid MSFlexGrid1, Form1
-
Mar 28th, 2000, 04:16 AM
#3
New Member
I'm not sure if this will help you, but following is a procedure I use to set the columns of a grid (in this case the DBGrid control) to the optimum size required to display the longest piece of data in any grid column on the currently shown rows of the grid. Hope it helps.
Lew.
PS: Sorry about the lack of indentation - it's in the original but I'm not sure if it will be there when you view it.
Public Sub Fit_Columns()
Dim i As Integer, j As Integer, L As Integer
Dim CWidths() As Integer
Dim BM As Variant
Screen.MousePointer = vbHourglass
ReDim CWidths(DBGrid1.Columns.Count)
If DBGrid1.VisibleRows > 0 Then
BM = DBGrid1.RowBookmark(0)
'NOTE: The next 8 lines of code are SUPER SLOW! I blame the DBGrid control
For i = 0 To DBGrid1.VisibleRows - 1
Data1.Recordset.Bookmark = DBGrid1.RowBookmark(i)
For j = 0 To DBGrid1.Columns.Count - 1
'The line *** below was replaced because of its slowness in
'retrieving DBGrid1.Columns(j).Text (fault with Apex DBGrid)
'L = TextWidth(DBGrid1.Columns(j).Text) ***
If Not IsNull(Data1.Recordset.Fields(j)) Then
If TextWidth(Data1.Recordset.Fields(j)) <= DBGrid1.Width Then
L = TextWidth(Data1.Recordset.Fields(j))
Else
L = DBGrid1.Width
End If
If L > CWidths(j) Then CWidths(j) = L
End If
Next j
If i < DBGrid1.VisibleRows - 1 Then DoEvents
Next i
Data1.Recordset.Bookmark = BM
For j = 0 To DBGrid1.Columns.Count - 1
If CWidths(j) < 200 Then CWidths(j) = 200
DBGrid1.Columns(j).Width = CWidths(j) + 100
Next j
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|