Groups | Blog | Home
all groups > dotnet general > october 2005 >

dotnet general : ListView - autosizing columns to fit data



ASGMikeG
10/31/2005 4:13:04 PM
Hi,
Does anyone have a bit of code that will auto-size the columns on a ListView
to fit the column headers AND data in those columns ?
Regards
Siva M
11/1/2005 12:00:00 AM
<msdn
url="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscolumnheaderclasswidthtopic.asp">

.... The ColumnHeader can be set to adjust at run time to the column contents
or heading. To adjust the width of the longest item in the column, set the
Width property to -1. To autosize to the width of the column heading, set
the Width property to -2.

</msdn>

However, you have to do the above for every column by looping through the
column collection.

[quoted text, click to view]
Hi,
Does anyone have a bit of code that will auto-size the columns on a ListView
to fit the column headers AND data in those columns ?
Regards
Michael

ASGMikeG
11/1/2005 1:49:10 PM
Many thanks - that gets me most of the way there !.

[quoted text, click to view]
AddThis Social Bookmark Button