在通常情况下,listview的列头是按钮式的,如果你想把列头做成平面式的,那就用下面的代码:
(转自:KaiDianLe.Com)
Option Explicit Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long,ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long,ByVal nIndex As Long,ByVal dwNewLong As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As Long,lParam As Any) As Long Private Const GWL_STYLE = (-16) Private Const LVM_FIRST = &H1000 Private Const LVM_GETHEADER = (LVM_FIRST + 31) Private Const HDS_BUTTONS = &H2 Private Sub Form_Load() Dim hHeader As Long,lStyle As Long Dim i As Integer ListView1.View = lvwReport With ListView1.ColumnHeaders .Add,"编号",500,lvwColumnLeft For i = 1 To 10 .Add,"内容项" & i,1000,lvwColumnRight Next End With hHeader = SendMessage(ListView1.hWnd,LVM_GETHEADER,ByVal 0&) lStyle = GetWindowLong(hHeader,GWL_STYLE) SetWindowLong hHeader,GWL_STYLE,lStyle Xor HDS_BUTTONS End Sub
代码效果图如下: