Auto-adjust Column Width of a Listview Control in VB6

The following function auto adjusts column width of listview controls in vb6. Just copy and paste the code below on your project and call the function after loading data on your listview control.

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

Comments

  1. thanks for this code

    ReplyDelete
  2. code to sort/group data in listview by number of delimiter/s . e.g.1,2,3;2,4,6,8;3,6,9,12....

    ReplyDelete
  3. code to sort/group data in listview by number of delimiter/s . e.g.1,2,3;2,4,6,8;3,6,9,12....group by semicolon(;)

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Create a Configuration.INI Files in VB6

How to Set Windows Form Always on Top of Other Applications in VB6

How to Minimize/Send an App Icon to System Tray in Visual Basic 6