How can I make ListView columns automatically resize programmatically?

I found some examples using Win32 api or modeling a combination of + + ( ctrl - + ) buttons using SendKeys , but at least using the SendKeys method, listview grabs the cursor and sets it to the hourglass until I press the Start button on my keyboard. What is the cleanest way to do this?

+4
source share
3 answers

It looks like calling myListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) will do what you want. I would have thought, just name it after adding the item.

More here

+17
source

According to MSDN , if you set the column width to -1, then it will log in to the widest element

+1
source

loop through all the columns and set the width to -1 after adding the content.

0
source

Source: https://habr.com/ru/post/1276653/


All Articles