What's the easiest way to resize each listview column according to the width of the data in them. Thanks in advance.
Printable View
What's the easiest way to resize each listview column according to the width of the data in them. Thanks in advance.
I use the following function to resize my listview columns.
Code:
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) As Long
Public Const LVM_FIRST As Long = &H1000
Public Sub LVAutoSizeColumn(lv As ListView, Optional Column As ColumnHeader = Nothing)
Dim c As ColumnHeader
''Should only resize those with items
If lv.ListItems.Count > 0 Then
If Column Is Nothing Then
For Each c In lv.ColumnHeaders
SendMessage lv.hWnd, LVM_FIRST + 30, c.Index - 1, -1
Next
Else
SendMessage lv.hWnd, LVM_FIRST + 30, Column.Index - 1, -1
End If
lv.Refresh
End If
End Sub
I use VB 6. I got error at this line..It said not define..
Public Sub LVAutoSizeColumn(lv As ListView, Optional Column As ColumnHeader = Nothing)
Also at this line, I got error
Public Const LVM_FIRST As Long = &H1000
If you are declaring it in your form then you have to make it Private instead. Could you specify the complete error description in LVAutoSizeColumn?