TREEVIEW WTH 2 root

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

TREEVIEW WTH 2 root

Post by sal21 »

How to load ALL data from table where the 2 root are MARE and MONTAGNA in field STRUTTURA?

Peraphs just post, but not found a solution in searching...
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TREEVIEW WTH 2 root

Post by HansV »

Pseudo-code:

Code: Select all

    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim nodMare As Node
    Dim nodMontagna As Node
    Dim nodChild As Node
    Dim sql As String
    
    Set cnn = New ADODB.Connection
    cnn.Open '...
    Set rst = New ADODB.Recordset
    
    With Me.TreeView1
        ' 1 - MARE
        Set nodMare = .Nodes.Add(Key:="Mare", Text:="Mare")
        sql = "SELECT * FROM PREZZI WHERE STUTTURA = 'MARE'"
        ' Open recordset on sql
        rst.Open '...
        ' Loop through the recordset
        Do While Not rst.EOF
            ' Add nodes with Relationship:=tvwChild
            Set nodChild = .Nodes.Add(Relative:="Mare", Relationship:=tvwChild, Text:=rst!IDTP)
            rst.MoveNext
        Loop
        ' Close the recordset
        rs.Close
        
        ' 2 - MONTAGNA
        Set nodMontagna = .Nodes.Add(Key:="Montagna", Text:="Montagna")
        sql = "SELECT * FROM PREZZI WHERE STUTTURA = 'MARE'"
        ' Open recordset on sql
        rst.Open '...
        ' Loop through the recordset
        Do While Not rst.EOF
            ' Add nodes with Relationship:=tvwChild
            Set nodChild = .Nodes.Add(Relative:="Mare", Relationship:=tvwChild, Text:=rst!IDTP)
            rst.MoveNext
        Loop
        ' Close the recordset
        rs.Close
    End With
    cnn.Close
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: TREEVIEW WTH 2 root

Post by sal21 »

HansV wrote:
18 Jul 2021, 13:03
Pseudo-code:

Code: Select all

    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim nodMare As Node
    Dim nodMontagna As Node
    Dim nodChild As Node
    Dim sql As String
    
    Set cnn = New ADODB.Connection
    cnn.Open '...
    Set rst = New ADODB.Recordset
    
    With Me.TreeView1
        ' 1 - MARE
        Set nodMare = .Nodes.Add(Key:="Mare", Text:="Mare")
        sql = "SELECT * FROM PREZZI WHERE STUTTURA = 'MARE'"
        ' Open recordset on sql
        rst.Open '...
        ' Loop through the recordset
        Do While Not rst.EOF
            ' Add nodes with Relationship:=tvwChild
            Set nodChild = .Nodes.Add(Relative:="Mare", Relationship:=tvwChild, Text:=rst!IDTP)
            rst.MoveNext
        Loop
        ' Close the recordset
        rs.Close
        
        ' 2 - MONTAGNA
        Set nodMontagna = .Nodes.Add(Key:="Montagna", Text:="Montagna")
        sql = "SELECT * FROM PREZZI WHERE STUTTURA = 'MARE'"
        ' Open recordset on sql
        rst.Open '...
        ' Loop through the recordset
        Do While Not rst.EOF
            ' Add nodes with Relationship:=tvwChild
            Set nodChild = .Nodes.Add(Relative:="Mare", Relationship:=tvwChild, Text:=rst!IDTP)
            rst.MoveNext
        Loop
        ' Close the recordset
        rs.Close
    End With
    cnn.Close
TKS.
I have changed a little part in code, but work!

hummmm...

How to add the little sign "+" to the left of each root?

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TREEVIEW WTH 2 root

Post by HansV »

Set the LineStyle property of the TreeView control to 1 - tvwRootLines and the Style property to 6 - tvwTreelinesPlusMinusText.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: TREEVIEW WTH 2 root

Post by sal21 »

HansV wrote:
18 Jul 2021, 14:19
Set the LineStyle property of the TreeView control to 1 - tvwRootLines and the Style property to 6 - tvwTreelinesPlusMinusText.
:clapping: :clapping: :clapping: :clapping:

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: TREEVIEW WTH 2 root

Post by sal21 »

sal21 wrote:
18 Jul 2021, 15:03
HansV wrote:
18 Jul 2021, 14:19
Set the LineStyle property of the TreeView control to 1 - tvwRootLines and the Style property to 6 - tvwTreelinesPlusMinusText.
:clapping: :clapping: :clapping: :clapping:
OPS....

Now have:

Code: Select all

Private Sub APRI_TREEVIEW()

    Dim NODMARE As Node
    Dim NODMONTAGNA As Node
    Dim NODCHILD As Node

    With Me.TreeView1
        '1-MARE
        Set NODMARE = .Nodes.Add(Key:="MARE", Text:="MARE")
        Set RS = New ADODB.Recordset
        RS.CursorLocation = adUseClient
        SQL = "SELECT * FROM PREZZI WHERE STRUTTURA='MARE'"
        RS.Open SQL, CON, adOpenForwardOnly, adLockReadOnly
        RS.Sort = ("IDTIP,TIPO")
        Do While Not RS.EOF
            ' Add nodes with Relationship:=tvwChild
            INDICE = RS!IDTIP & "-" & RS!TIPO & "-DAL: " & RS!DAL & "-AL: " & RS!AL
            Set NODCHILD = .Nodes.Add(Relative:="MARE", Relationship:=tvwChild, Text:=INDICE)
            RS.MoveNext
        Loop
        RS.Close
        Set RS = Nothing

        '2-MONTAGNA
        Set NODMONTAGNA = .Nodes.Add(Key:="MONTAGNA", Text:="MONTAGNA")
        Set RS = New ADODB.Recordset
        RS.CursorLocation = adUseClient
        SQL = "SELECT * FROM PREZZI WHERE STRUTTURA='MONTAGNA'"
        RS.Open SQL, CON, adOpenForwardOnly, adLockReadOnly
        RS.Sort = ("IDTIP,TIPO")
        Do While Not RS.EOF
            ' Add nodes with Relationship:=tvwChild
            INDICE = RS!IDTIP & "-" & RS!TIPO & "-DAL: " & RS!DAL & "-AL: " & RS!AL
            Set NODCHILD = .Nodes.Add(Relative:="MONTAGNA", Relationship:=tvwChild, Text:=INDICE)
            RS.MoveNext
        Loop
        RS.Close
        Set RS = Nothing
    End With

End Sub

now from table PRENOTAZIONI and based the range DAL to AL, i need to appen on related node a sub node....

for example:

node:

1-SINGOLA DAL 01/06/2021 AL 31/07/2021
10 SINGOLA 05/06/2021 09/06/2021
11 SINGOLA 08/06/2021 13/06/2021
11 SINGOLA 15/06/2021 21/06/2021
10 SINGOLA 15/06/2021 21/06/2021
10 SINGOLA 01/07/2021 08/07/2021
Ecc...
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TREEVIEW WTH 2 root

Post by HansV »

I cant test this, so you'll just have to try this and correct it if necessary.
Add the following declarations:

Code: Select all

    Dim NODSUBCHILD As Node
    Dim RS2 As ADODB.Recordset
    Dim INDICE2 As String
Here is the code for MARE. It'll be similar for MONTAGNA.

Code: Select all

        Do While Not RS.EOF
            ' Add nodes with Relationship:=tvwChild
            INDICE = RS!IDTIP & "-" & RS!TIPO & "-DAL: " & RS!DAL & "-AL: " & RS!AL
            Set NODCHILD = .Nodes.Add(Key:=INDICE, Relative:="MARE", Relationship:=tvwChild, Text:=INDICE)
            Sql = "SELECT * FROM PRENOTAZIONI WHERE STRUTTURA = 'MARE' AND IDTIP = " & RS!IDTIP & " AND DAL Between #" & _
                Format(RS!DAL, "mm/dd/yyyy") & "# And #" & Format(RS!AL, "mm/dd/yyyy")
            Set RS2 = New ADODB.Recordset
            RS2.CursorLocation = adUseClient
            RS2.Open Sql, CON, adOpenforwardOnly, adLockReadOnly
            Do While Not RS2.EOF
                INDICE2 = RS2!IDTIP & "-" & RS2!TIPO & "-DAL: " & RS2!DAL & "-AL: " & RS2!AL & "-" & RS2!IDCLI
                Set NODSUBCHILD = .Nodes.Add(Relative:=INDICE, Relationship:=tvwChild, Text:=INDICE2)
                RS2.MoveNext
            Loop
            RS2.Close
            RS.MoveNext
        Loop
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: TREEVIEW WTH 2 root

Post by sal21 »

HansV wrote:
18 Jul 2021, 20:22
I cant test this, so you'll just have to try this and correct it if necessary.
Add the following declarations:

Code: Select all

    Dim NODSUBCHILD As Node
    Dim RS2 As ADODB.Recordset
    Dim INDICE2 As String
Here is the code for MARE. It'll be similar for MONTAGNA.

Code: Select all

        Do While Not RS.EOF
            ' Add nodes with Relationship:=tvwChild
            INDICE = RS!IDTIP & "-" & RS!TIPO & "-DAL: " & RS!DAL & "-AL: " & RS!AL
            Set NODCHILD = .Nodes.Add(Key:=INDICE, Relative:="MARE", Relationship:=tvwChild, Text:=INDICE)
            Sql = "SELECT * FROM PRENOTAZIONI WHERE STRUTTURA = 'MARE' AND IDTIP = " & RS!IDTIP & " AND DAL Between #" & _
                Format(RS!DAL, "mm/dd/yyyy") & "# And #" & Format(RS!AL, "mm/dd/yyyy")
            Set RS2 = New ADODB.Recordset
            RS2.CursorLocation = adUseClient
            RS2.Open Sql, CON, adOpenforwardOnly, adLockReadOnly
            Do While Not RS2.EOF
                INDICE2 = RS2!IDTIP & "-" & RS2!TIPO & "-DAL: " & RS2!DAL & "-AL: " & RS2!AL & "-" & RS2!IDCLI
                Set NODSUBCHILD = .Nodes.Add(Relative:=INDICE, Relationship:=tvwChild, Text:=INDICE2)
                RS2.MoveNext
            Loop
            RS2.Close
            RS.MoveNext
        Loop
LITTLE modify and code work perfect!
tks bro!