I want some Moore

Blog about stuff and things and stuff. Mostly about SQL server and .Net
posts - 218, comments - 2281, trackbacks - 33

My Links

Advertisement

News

Hi! My name is 
Mladen Prajdić  I'm from Slovenia and I'm currently working as a .Net (C#) and SQL Server developer.

I also speak at local user group meetings and conferences like SQLBits and NT Conference
Welcome to my blog.
SQL Server MVP

My Books

SQL Server MVP Deep Dives 2
The Red Gate Guide to SQL Server Team based Development Free e-book

My Blog Feed via Email
Follow MladenPrajdic on Twitter


Users Online: who's online

Article Categories

Archives

Post Categories

Cool software

Other Blogs

Other stuff

SQL stuff

.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

Print | posted on Wednesday, August 29, 2007 7:25 PM | Filed Under [ .Net ]

Feedback

Gravatar

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

Are you insane ???? This is madness!
8/29/2007 8:40 PM | Jeff
Gravatar

# 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. :)
8/29/2007 8:42 PM | Mladen
Gravatar

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

Sorry, I couldn't resist! :)
8/29/2007 10:18 PM | Jeff
Gravatar

# 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
8/30/2007 6:05 PM | DuncanS
Gravatar

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

i knew i forgot to put in something... thanx Duncan!
8/30/2007 6:08 PM | Mladen
Gravatar

# 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!

9/1/2007 5:40 AM | Eric W. Bachtal
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET