开发者

Auto widths in ListView [duplicate]

开发者 https://www.devze.com 2023-02-22 12:43 出处:网络
This question already has answers here: C# ListView Column Width Auto (10 answers) 开发者_如何学JAVA
This question already has answers here: C# ListView Column Width Auto (10 answers) 开发者_如何学JAVA Closed 9 years ago.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消