Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView Example

Status
Not open for further replies.

fabby1

Technical User
Mar 9, 2004
206
GB
Hi

Can anybody give me an example of using a TreeView I have tried using a VB6 example but it doesn't seem to work

If anybody has an Access Specific example I would be grateful

Regards

Phil
 
Better late than never.

Code:
Private Sub Form_Load()

    'Build the Nodes for the TreeView Control
    With MyTreeView.Nodes
        'Parent node
        .Add , , "QAPARENT", "QA Team", "img1"
        'Child nodes
        .Add "QAPARENT", tvwChild, , "Bug Input", "img2"
        .Add "QAPARENT", tvwChild, "VIEWBUG", "View Bugs", "img3"
        'Parent node
        .Add , , "DEVPARENT", "Dev Team", "img4"
        'Chile nodes
        .Add "DEVPARENT", tvwChild, , "Statistics", "img1"
        .Add "DEVPARENT", tvwChild, , "Find", "img2"
        .Add "DEVPARENT", tvwChild, , "Tasks", "img3"
    End With
    
        
End Sub

Example with a recordset (with french comments)

Code:
Sub RemplirTreeview()
    ' définition des variables
    Dim RSEntites As DAO.Recordset
    Dim txtSQL As String
    Dim j     As Integer
    Dim mynode As Node
    ' ouverture de la requête du formulaire en cours
    Set mabase = CurrentDb
    txtSQL = "SELECT * FROM R_Entite_triee;"
    Set RSEntites = mabase.OpenRecordset(txtSQL, dbOpenSnapshot)
    ' instanciation de l'objet treeview
    Set trwArbo = Me.TV1.Object
    With trwArbo
        .Nodes.Clear
        .ImageList = Me.ImageList1.Object
        .HideSelection = False
        .LineStyle = tvwRootLines
    End With

'remplissage du treeview avec le contenu de la requête
Do While Not RSEntites.EOF
    'niveau1
    If IsNull(RSEntites![N°entiteS]) = True Then
        Set mynode = trwArbo.Nodes.Add(, , "O" & RSEntites![N°Entite], RSEntites![Entite], "IMG_FOLD")
        'mynode.Bold = True
        'mynode.ForeColor = RGB(98, 162, 197)
    Else
    'niveaux2 à 4
        Select Case Left(RSEntites![TypeEntite], 1)
            Case 2
                trwArbo.Nodes.Add "O" & RSEntites![N°entiteS], tvwChild, "O" & RSEntites![N°Entite], RSEntites![Entite], "IMG_FOLD"
            Case 3
                trwArbo.Nodes.Add "O" & RSEntites![N°entiteS], tvwChild, "O" & RSEntites![N°Entite], RSEntites![Entite], "IMG_FOLD"
            Case 4
                trwArbo.Nodes.Add "O" & RSEntites![N°entiteS], tvwChild, "O" & RSEntites![N°Entite], RSEntites![Entite], "IMG_PICK"
        End Select
    End If
    RSEntites.MoveNext
Loop

'libération du recordset
Set RSEntites = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top