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 Const LVM_SETCOLUMNWIDTH = &H1000 + 30 Const LVSCW_AUTOSIZE = 65535 Const LVSCW_AUTOSIZE_USEHEADER = 65534 ' adjust the width of a ListView control so that each item is fully visible ' if second argument is True, column headers' width is also taken into account Sub ListViewAdjustColumnWidth(LV As ListView, Optional AccountForHeaders As _ Boolean) Dim col As Integer, lParam As Long If AccountForHeaders Then lParam = LVSCW_AUTOSIZE_USEHEADER Else lParam = LVSCW_AUTOSIZE End If For col = 1 To LV.ColumnHeaders.Count SendMessage LV.hwnd, LVM_SETCOLUMNWIDTH, col, lParam Next End Sub |