Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    gerarchie con treeview in VB6

    Salve a tutti.
    Dovrei creare in vb6 una treeview con n gerarchie padre-figlio.
    Vuol dire che la root è sempre una,ma il node di quella root puo' avere altri nodes o delle leaf.
    come posso rendere il tutto dinamico?
    e' meglio gestire da codice o lavorare su una funzione del db?(io uso sqlserver 2000)E se sì,come?


    Grazie a tutti

  2. #2
    Io utilizzo anche il DB sistemato in modo gerarchico, ossia: ogni record ha un suo id e l'id del padre. Poi utilizzo una funzione ricorsiva per caricare padri e figli.

    codice:
    Private Function Carica_Tree(Espandi As Boolean, ID_Father As Long, StrFather As String)
        Dim RS_1 As New ADODB.Recordset
        
        Screen.MousePointer = 11
        If ID_Father <> 0 Then
            Sql = "SELECT TABELLA.ID,"
            Sql = Sql & " TABELLA.ID_Padre,"
            Sql = Sql & " TABELLA.Descrizione,"
            Sql = Sql & " TABELLA_Figli.ID_Padre AS Father_Figlio"
            Sql = Sql & " FROM TABELLA LEFT JOIN "
            Sql = Sql & " TABELLA AS TABELLA_FIGLI ON TABELLA.ID ="
            Sql = Sql & " TABELLA_Figli.ID_Padre"
            Sql = Sql & " WHERE TABELLA.ID_Padre =" & ID_Father
            Sql = Sql & " GROUP BY TABELLA.ID, TABELLA.ID_Padre,"
            Sql = Sql & " TABELLA.Descrizione, TABELLA_Figli.ID_Padre"
            ContaQuery = ContaQuery + 1
        Else
            IndiceCar = 0
            Sql = "SELECT * FROM TABELLA"
            Sql = Sql & " WHERE ID_Father =0"
            ContaQuery = ContaQuery + 1
        End If
        Sql = Sql & " ORDER BY TABELLA.Descrizione"
        Cont = 0
        If ID_Father = 0 Then
            On Error Resume Next
            Rs.CacheSize = 150
            On Error GoTo 0
            Rs.Open Sql, Application.Databases.Selected.Connection, adOpenForwardOnly
            'LIVELLO 1
            If Rs.EOF = False Then
                Do While Rs.EOF = False
                    Set NodX = Tree.Nodes.Add(, , StrFather & Rs!ID, Rs!Descrizione)
                    ContaP = ContaP + 1
    	    'Richiamo la stessa funzione
                    Carica_Tree Espandi, Rs!ID, StrFather
                    StrFather = "Fat"
                    Rs.MoveNext
                Loop
            End If
            For Cont = 1 To Tree.Nodes.Count - 1
                Tree.Nodes(Cont).Expanded = Espandi
            Next
            If IndiceCar > 0 Then
    	If Tree.Nodes.Item(IndiceCar).Parent Is Nothing Then
    	   Tree.Nodes.Item(IndiceCar).Root.Selected = True
    	   Tree.Nodes.Item(IndiceCar).Root.Expanded = True
    	   Set Tree.DropHighlight = Tree.Nodes.Item(IndiceCar).Root
    	Else
    	   Tree.Nodes.Item(IndiceCar).Parent.Selected = True
    	   Tree.Nodes.Item(IndiceCar).Parent.Expanded = True
    	   Set Tree.DropHighlight = Tree.Nodes.Item(IndiceCar).Parent
    	End If
            End If
            Set Rs = Nothing
        Else
            'LIVELLI 2 ==> N
            If StrFather = "Fat" Then
                Conta = 1
            Else
                Conta = 0
            End If
            On Error Resume Next
            RS_1.CacheSize = 150
            On Error GoTo 0
            RS_1.Open Sql, Application.Databases.Selected.Connection, adOpenForwardOnly
            If RS_1.EOF = False Then
                Do While RS_1.EOF = False
                    If Conta = 1 Then
                        Set NodX = Tree.Nodes.Add("Fat" & ID_Father, tvwChild, _
                        "Son" & RS_1!ID, RS_1!Descrizione)
                    Else
                        Set NodX = Tree.Nodes.Add(StrFather & ID_Father, tvwChild, _
                        "Son" & RS_1!ID, RS_1!Descrizione)
                    End If
                    If RS_1!ID = ID_Touch Then
                        If IndiceCar = 0 Then
                            IndiceCar = NodX.Index
                        End If
                    End If
                    ContaP = ContaP + 1
                    StrFather = "Son"
                    If IsNull(RS_1!Father_Figlio) = False Then
                        Carica_Tree Espandi, RS_1!ID, StrFather
                    End If
                    RS_1.MoveNext
                Loop
            End If
            Set RS_1 = Nothing
        End If
    End Function
    Spero si capisca, sono in ufficio e non ho molto tempo...
    The Fresh...remaker
    A volte la risposta è sotto ai nostri occhi, bisogna solo aver voglia di cercarla!!
    http://www.angelsinthedark.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.