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


This demo will show you how to auto fit all ListView items.

Step-By-Step Example

- Create a standard exe project
- Add ListView control on the form1. To add ListView control you need to add reference to Microsoft Windows Common Control 5.0 (Click Project->Components)
- Place the following code in form1 code window

Form1.frm

Click here to copy the following block
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

Private Sub AutosizeColumns(ByVal TargetListView As ListView)

  Const SET_COLUMN_WIDTH  As Long = 4126
  Const AUTOSIZE_USEHEADER As Long = -2

  Dim lngColumn As Long

  For lngColumn = 0 To (TargetListView.ColumnHeaders.Count - 1)

    Call SendMessage(TargetListView.hwnd, _
        SET_COLUMN_WIDTH, _
        lngColumn, _
        ByVal AUTOSIZE_USEHEADER)

  Next lngColumn

End Sub

Private Sub Form_Load()
  Call LoadListView

  '//Auto size all columns of listview
  Call AutosizeColumns(ListView1)
End Sub
Sub LoadListView()
  Dim i As Integer
  Dim itmX As ListItem

  ListView1.ListItems.Clear
  ListView1.ColumnHeaders.Clear

  With ListView1
    .View = lvwReport

    .ColumnHeaders.Add , , "MyHeaderrrrrrrrrr1"
    .ColumnHeaders.Add , , "MyHeaderrrrrrrrrr2"
    .ColumnHeaders.Add , , "MyHeaderrrrrrrrrr3"

    For i = 1 To 10
      'ListItems are always shown in the first column.
      Set itmX = .ListItems.Add
      With itmX
        .Text = "long itemmmmmmmmmmmmmm" & i
        .SubItems(1) = "long sub itemmmmmmmmmmmmmm1-" & i
        .SubItems(2) = "long sub itemmmmmmmmmmmmmm2-" & i
      End With
    Next
  End With
End Sub

- Press F5 to run the demo


Audit, Notify, Deploy and Manage SSIS
Download the Free 30-day Trial Version...Learn More About This Product...

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   |  Blogs

© 2008 BinaryWorld LLC. All rights reserved.