Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a ListView's columns auto-resize programmatically?

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?

like image 448
Luke Avatar asked Sep 11 '08 20:09

Luke


2 Answers

Looks like a call to myListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) will do what you want. I would think, just call it after adding an item.

More info here

like image 125
Matt Nelson Avatar answered Nov 15 '22 04:11

Matt Nelson


According to MSDN, if you set the column width to -1 then it will autosize to the widest item

like image 27
rpetrich Avatar answered Nov 15 '22 05:11

rpetrich