Home » Controls » How to Autosizing List View Headers
How to Autosizing List View Headers
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 'Controls - How to Autosizing List View Headers Option Explicit 'If the user resized the headers at runtime, and caused some headers to be out of the 'listview visible range, you can use the code below to resize the headers in way that 'all of them will be visible. 'Add a ListView Control and a Command Button to your form and Set the ListView View 'property to 3 - lvwReport. Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Const LVM_FIRST = &H1000 Public Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30) Public Const LVSCW_AUTOSIZE = -1 Public Const LVSCW_AUTOSIZE_USEHEADER = -2 Private Sub Form_Load() 'the code below add 3 headers to the ListView With ListView1 .ColumnHeaders.Add , , "Header 1" .ColumnHeaders.Add , , "Header 2" .ColumnHeaders.Add , , "Header 3" End With End Sub Private Sub Command1_Click() Dim iColumn As Long, iCount As Long iCount = 0 For iColumn = iCount To ListView1.ColumnHeaders.Count - 2 SendMessage ListView1.hWnd, LVM_SETCOLUMNWIDTH, iColumn, LVSCW_AUTOSIZE_USEHEADER Next iColumn End Sub |
Enjoy this article?
Filed under: Controls
Leave a comment