Hey y'all :)
Is it possible to resize a flexgrid's column width to fit the widest item in the column, or is it possible to loop through a recordset and find the widest string and size it according to that?
Cheers
Des
Printable View
Hey y'all :)
Is it possible to resize a flexgrid's column width to fit the widest item in the column, or is it possible to loop through a recordset and find the widest string and size it according to that?
Cheers
Des
ok, thanks for the help y'all... (sarcastically)(just kiddin...)
Found it :)
VB Code:
For y = 0 To Grid.Cols - 1 objRS.MoveFirst Grid.Col = y z = 0 For x = 0 To Grid.Rows - 1 Grid.Row = x If TextWidth(Grid.Text) > z Then z = TextWidth(Grid.Text) Next x Grid.ColWidth(y) = z +100 ' 100 or whatever extra Next y
turn off redraw first, turn it on again after, et voila.
Des
Where does this code go..In the FormLoad?
It goes after you load the data into the grid (which depends on your program.Quote:
Where does this code go..In the FormLoad?
Anyway desflynn, your code does the job, but this is slightly faster (as it doesn't change the row/column):
VB Code:
Dim max_width as Long Dim tmp_width as Long With Grid .Redraw = False For y = 0 To .Cols - 1 max_width = 0 For x = 0 To .Rows - 1 tmp_width = TextWidth(.TextMatrix(x,y)) If tmp_width > max_width Then max_width = tmp_width Next x .ColWidth(y) = max_width +100 ' 100 or whatever extra Next y .Redraw = True End With
And rather than 100 I would recommend using Screen.TwipsPerPixelX * 5, as it will be the same size on all computers (the usual measurement unit - Twips - can vary between computers)