Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

ListView - autosize column widths


Public 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 =   - 1
Const LVSCW_AUTOSIZE_USEHEADER = - 2

'LV is the ListView control
Dim col As Long
For col = 0 To LV.ColumnHeaders.Count - 1
   SendMessage LV.hwnd, LVM_SETCOLUMNWIDTH, col, LVSCW_AUTOSIZE_USEHEADER
Next col