It goes after you load the data into the grid (which depends on your program.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)




Reply With Quote