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

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist