devxlogo

ListViewAdjustColumnWidth – Resize ListView’s columns to account for their contents

ListViewAdjustColumnWidth – Resize ListView’s columns to account for their contents

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA"(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParamAs Long) As LongConst LVM_SETCOLUMNWIDTH = &H1000 + 30Const LVSCW_AUTOSIZE = -1Const LVSCW_AUTOSIZE_USEHEADER = -2' Adjust the width of a ListView control so that each item is fully visibleif second' argument is True, column headers' width is also taken into account.Sub ListViewAdjustColumnWidth(LV As ListView, Optional AccountForHeaders AsBoolean)    Dim col As Integer, lParam As Long    If AccountForHeaders Then        lParam = LVSCW_AUTOSIZE_USEHEADER    Else        lParam = LVSCW_AUTOSIZE    End If    For col = 0 To LV.ColumnHeaders.Count - 1        SendMessageLong LV.hwnd, LVM_SETCOLUMNWIDTH, col, lParam    NextEnd Sub

devx-admin

Share the Post: