PC Review


Reply
Thread Tools Rate Thread

Calculating ListView width

 
 
Simanovsky
Guest
Posts: n/a
 
      25th Aug 2003
Hello all,

Could anybody advice how to calculate the width of the
widest item in the ListView?

I need to resize a ListView according to the size of the
strings stored in it, particulary to avoid horizontal
scrolling. To calculate the new dimensions of the control
I tried both overloads of ListView.GetItemRect() while
setting View to View.List and View.Details. But
GetItemRect seems always to return same value for all
indices and setting control width to that does not ensure
absence of horizontal scrolling.

Thanks in advance,
Simanovsky
 
Reply With Quote
 
 
 
 
Len Weaver
Guest
Posts: n/a
 
      25th Aug 2003
Hello Simanovsky,

> Could anybody advice how to calculate the width of the
> widest item in the ListView?
>
> I need to resize a ListView according to the size of the
> strings stored in it, particulary to avoid horizontal
> scrolling. To calculate the new dimensions of the control


This feature is built in to the .net ListView. After you've added
rows to the ListView, execute this code:

<Untested code>
foreach( ColumnHeader c in lvwMyListView.Columns )
c.Width = -2;
</Untested code>

Setting the width to -2 will resize a column to accomodate the
longest string in that column (in Details view).

Hope this helps,
Len


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.net 2.0 listview last column width Sid Price Microsoft Dot NET Framework 1 16th Nov 2007 12:42 AM
width of listview Sbroeff Microsoft Dot NET Framework Forms 5 27th Oct 2006 03:12 PM
width of listview's columns Sbroeff Microsoft VB .NET 1 25th Oct 2006 03:09 PM
Listview column width Alex Bibiano Microsoft C# .NET 1 29th Mar 2006 10:46 AM
ListView Last Column Width Just Me Microsoft VB .NET 2 15th Jul 2004 05:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:51 AM.