I've found some examples using the Win32 api or simulating the ^+ button combination (ctrl-+) using SendKeys, but at least with the SendKeys method the listview grabs the cursor and sets it to an hourglass until I hit the start button on my keyboard. What is the cleanest way to do this?
A:
Can you be more specific about what "auto-resize" means? Do you mean you want them to shuffle around when the window (and list view) change size, or do you want them to resize based on the length of the data they're showing?
Andrew
2008-09-11 21:12:14
I want them to resize based on the length of the data they're showing.
Luke
2008-09-11 21:24:08
+1
A:
According to MSDN, if you set the column width to -1 then it will autosize to the widest item
rpetrich
2008-09-11 21:14:37
This doesn't seem to work for me. I'm adding listviewitems at run-time and the columns stay skinny.
Luke
2008-09-11 21:27:12
Weird. Perhaps the ListView needs to be visible and with the items added already. Or perhaps a call to Application.DoEvents might do the trick?You could always try sending LVSCW_AUTOSIZE yourself using P/Invoke: http://vbnet.mvps.org/index.html?code/comctl/lvcolumnautosize.htm (link for VB6)
rpetrich
2008-09-11 21:35:33
Have you tried wrapping the list view updates in BeginUpdate()/EndUpdate() brackets? Maybe the -1 trick works when you specifically end the update, triggering a recalc of the way the list view is displayed.
Andrew
2008-09-13 10:48:58