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
Post a Comment