This question already has an answer here:
-
C# ListView Column Width Auto
10 answers
How can we set the width of each column according to the length of its content in a ListView? I hate having to keep changing the size of each column at runtime. Is there an MSDN doc that has this info? I can't find where I should be looking
Thank you
Review the ColumnHeader.AutoResize() method. Call it after populating the Items, the form's OnLoad() method is the first chance.
Use both resizing options after populating the list:
myListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
myListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
This will size columns to the width of column data, and then restore minimum width for column headers without completely trashing the original auto-sizing.
I got it:
viewer.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);