Start / FAQ / FAQ 0146: Warum funktioniert FullRowSelect im TreeView nicht?
 
Startseite Up-/Download Tutorials Club Das Team
Rubriken Foren Bücher Tips 'n Tricks Suche


FAQ 0146: Warum funktioniert FullRowSelect im TreeView nicht?


  Frage

Warun funktioniert die Eigenschaft „FullRowSelect“ für das TreeView nicht?

  Antwort

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.

'   Modul
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)

'------------------------------------------------------
' Funktion     : TreeviewFullRowSelect
' Beschreibung : FullRowSelect bei einem Treeview einstellen
' Übergabewert : Trv = TreeView
'                Optional FullRowSelect = True (einschalten)
'                                       = False (ausschalten)
' Rückgabewert : True = Aktion war erfolgreich
'                False = Aktion war nicht erfolgreich
'------------------------------------------------------
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 Function

Listing 1: Workaround für den FullRowSelect-Fehler

'   Formular
Option Explicit
    
Private Sub Form_Load()
    ' FullRowSelect für das TreeView1 aktivieren
    Call TreeviewFullRowSelect(TreeView1, True)

    ' FullRowSelect für das TreeView1 deaktivieren
    ' Call (TreeviewFullRowSelect(TreeView1, False))

    Call TreeView1.Nodes.Add(, , "a", "Nodetext")
    Call TreeView1.Nodes.Add("a", tvwChild, "b", "Nodetext")
End Sub

Listing 2: Beispiel eines Aufrufs


Erstellt: 05.06.2006
Aktualisierung: 26.07.2010
  Autor: Frank Schüler
E-Mail: faq@ActiveVB.de



Copyright © 1998-2010 by ActiveVB
Alle Rechte vorbehalten.