Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Determine the optimal width for ListView columns

Total Hit ( 2966)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Here's a simple but effective trick to ensure that the column of a ListView control is wide enough to display the entire string you're assigning to the column title or to an element. Just drop a Label on the form, set its Autosize property to True and Visible property to False. Also, ensure that the Label control has a Font property that matches the one used for the ListView.

Then, when you want to ensure that a string will be displayed correctly in the ListView, just assign it to the Label control first, and then compare the Label's Width property with the width of the ListView column:

Click here to copy the following block
Dim text As String

  text = "A very long string added to the ListView"
  ' Add a couple of spaces for good measure.
  Label1.Caption = text & " "

  ' Compare current column width with Label's width  
  If ListView1.ColumnHeaders(1).Width < Label1.Width Then
    ' make the column wider if necessary
    ListView1.ColumnHeaders(1).Width = Label1.Width
  End If
  
  ListView1.ListItems.Add , , text


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.