直接修改TREEVIEW控件的样式就可以。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 Const GWL_STYLE = (-16) Private Const TVS_SINGLEEXPAND = &H400Private Sub Command1_Click() Dim lStyle As Long
lStyle = GetWindowLong(TreeView1.hwnd, GWL_STYLE) lStyle = lStyle Or TVS_SINGLEEXPAND SetWindowLong TreeView1.hwnd, GWL_STYLE, lStyle End Sub
用 Microsoft Windows Common Controls 6.0 版本的控件,直接设属性 SingleSel = True 就可以了。
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const TVS_SINGLEEXPAND = &H400Private Sub Command1_Click()
Dim lStyle As Long
lStyle = GetWindowLong(TreeView1.hwnd, GWL_STYLE)
lStyle = lStyle Or TVS_SINGLEEXPAND
SetWindowLong TreeView1.hwnd, GWL_STYLE, lStyle
End Sub