I'd like a large pepperoni pizza... oh wait, no flexgrid. I've got one, just started learning how to use the buggers, they're kinda neat. I'd like to have some code that will make the widths all fit to text. Like when you double click on the resizing bar in most microsoft programs. Any thoughts? Thanks!
** EDIT - this is very old and dubious code, see here for a much better version! **
Here's the code you need (you can just chuck it into a module or form). I've forgotten which programs actually use it, so you'll have to work out for yourself when the mouse is clicked in the right place!
VB Code:
Sub flxAutoSizeColumns(gridName, owner_hwnd, _
Optional ByVal include_headers As Boolean = True, _
Optional ByVal min_col = 0, Optional max_col)
'Set flexgrid column widths to the minimum for viewing all text
With gridName
If include_headers Then 'set top row to check
first_row = 0
Else
first_row = .fixed_rows
End If
If IsMissing(max_col) Then max_col = .Cols - 1
For tmp_col = min_col To max_col 'for each column...
curr_max = 0
For tmp_row = first_row To .Rows - 1 '...find widest text
yep, if you have vb6 you can drop the "GetVisualLength" stuff, replace the line in the first module with <formname>.TextWidth, and change the last line to: .ColWidth(tmp_col) = 50 + curr_max
(or you could just change the multiplier in the last bit!)
There is no reason to ressurrect the dead! This thread is 9 years old. Try the solution linked to in post #2.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672