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
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.
Review the ColumnHeader.AutoResize() method. Call it after populating the Items, the form's OnLoad() method is the first chance.
I got it:
viewer.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
精彩评论