| Die Eigenschaft „FullRowSelect“ für das TreeView steht erst mit der Version 6 der Microsoft Windows Common Controls zur Verfügung. Allerdings hat diese Eigenschaft einen Bug: Man kann zwar in der Entwicklungsumgebung oder zur Laufzeit diese Eigenschaft setzen, aber der Effekt „FullRowSelect“ wird nicht ausgeführt. Über einen kleinen Umweg lässt sich jedoch die Eigenschaft „FullRowSelect“ nutzen. 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 Const TVS_FULLROWSELECT As Long = &H1000
Private Const GWL_STYLE As Long = (-16)
Public Function TreeviewFullRowSelect( _
ByVal Trv As TreeView, _
Optional ByVal FullRowSelect As Boolean = True _
) As Boolean
Dim lngCurrentStyle As Long
Dim Result As Long
lngCurrentStyle = GetWindowLong(Trv.hwnd, GWL_STYLE)
If FullRowSelect Then
lngCurrentStyle = lngCurrentStyle Or TVS_FULLROWSELECT
Else
If (lngCurrentStyle And TVS_FULLROWSELECT) = _
TVS_FULLROWSELECT Then
lngCurrentStyle = lngCurrentStyle Xor TVS_FULLROWSELECT
End If
End If
Result = SetWindowLong(Trv.hwnd, GWL_STYLE, lngCurrentStyle)
Call Trv.Refresh
DoEvents
TreeviewFullRowSelect = (Result <> 0)
End FunctionListing 1: Workaround für den FullRowSelect-Fehler Option Explicit
Private Sub Form_Load()
Call TreeviewFullRowSelect(TreeView1, True)
Call TreeView1.Nodes.Add(, , "a", "Nodetext")
Call TreeView1.Nodes.Add("a", tvwChild, "b", "Nodetext")
End SubListing 2: Beispiel eines Aufrufs |