Mladen Prajdić Blog

Blog about stuff and things and stuff. Mostly about SQL server and .Net

.Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.

A negative Width value??

I can hear it now:

Are you insane Mladen?? Do you want our apps going around looking ugly??

Well... of course I do! It means i can go around fixing them for big bucks :))

 

But joking aside, -1 and -2 width values are very usefull.

 

Setting the width to be -1 means that the column will have the width of the longest item in it.

Setting the width to be -2 means that the column will have the width of the column heading.

 

Pretty cool, no?

 

kick it on DotNetKicks.com

Legacy Comments


Jeff
2007-08-29
re: .Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.
Are you insane ???? This is madness!

Mladen
2007-08-29
re: .Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.
hmm... so now i'm not sure if you're being serious or not, jeff. :)

Jeff
2007-08-29
re: .Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.
Sorry, I couldn't resist! :)

DuncanS
2007-08-30
re: .Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.columnheader.width(VS.71).aspx

Mladen
2007-08-30
re: .Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.
i knew i forgot to put in something... thanx Duncan!

Eric W. Bachtal
2007-09-01
re: .Net Windows Forms ListView ColumnHeader width tip. Set it to -1 or -2.
It seems little jewels like this pop up and get forgotten again every other year. I posted about it back in 2003, including doing the same with API calls in VB6, which isn't important, except that there was a comment left there that may prove helpful to someone.

http://ewbi.blogs.com/develops/2003/10/resizing_listvi.html

Specifically, the commenter had a problem with the autosizing of the last column not happening, which was only solved by setting the width to -2 *after* filling the ListView with data. Not sure if this has been resolved in later versions of .NET.

Thanks for shining light again on this obscure setting!