自动调整listview标题头宽度的二种方法
方法一:
'*******************************
'用法:Call ResizeListView(ListView1)
'*******************************
Public Sub ResizeListview(objListView As ListView)
Dim dSecWidth As Double
Dim iLoop As Integer
With objListView
dSecWidth = (.Width / .ColumnHeaders.Count) - 30
For iLoop = 1 To .ColumnHeaders.Count
.ColumnHeaders(iLoop).Width = dSecWidth
'// DoEvents [ Optional, don't really need it ]
Next iLoop
End With
End Sub
方法二(使用API):
'**********************
'API声明
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_FIRST = &H1000
'函数
Public Sub AutoSizeColumnHeader(LView As ListView, Column As ColumnHeader, ByVal SizeToHeader As Boolean)
Dim l As Long
If SizeToHeader Then l = -2 Else l = -1
Call SendMessage(LView.hWnd, LVM_FIRST + 30, Column.Index - 1, l)
End Sub