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

Post a Comment

Popular posts from this blog

How to Create a Configuration.INI Files in VB6

How to Make Windows Form Transparent using Visual Basic 6/VB6

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