dcsimg
Results 1 to 3 of 3

Thread: how to treeview this reordset

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,847

    how to treeview this reordset

    in tabl1 have 3 fileds:

    REG (is a mom agency)
    BIG_AG (is a son agency of REG)
    LITTLE_AG (is a son of BIG_AG)

    example:
    REG BIG_AG ITTLE_AG
    900 901 001
    700 890 012
    700 890 014
    500 090 016
    700 908 014
    800 620 092

    i need a treeview, and if i click on item expand the related items

    900
    ...901
    ......001

    700
    ...890
    .......012
    .......014

    500
    ...090
    ......016

    800
    ...620
    .......092

    How to?

    note:
    using the select distint recordset in query

  2. #2
    Member gilman's Avatar
    Join Date
    Jan 2017
    Posts
    42

    Re: how to treeview this reordset

    Try this:
    Code:
    Private Sub LoadTreeView()
        Dim REG As String
        Dim BIG_AG As String
        Dim RS As ADODB.Recordset
        Set RS = New ADODB.Recordset
        
        RS.Open "SELECT DISTINCT REG, BIG_AG, LITTLE_AG FROM tabl1 ORDER BY REG, BIG_AG, LITTLE_AG", ADOCONN, adOpenForwardOnly
        
        While Not RS.EOF
            If REG <> RS!REG Then
                REG = RS!REG
                BIG_AG = ""
                TreeView.Nodes.Add , , REG, REG
            End If
            If BIG_AG <> RS!BIG_AG Then
                BIG_AG = RS!BIG_AG
                TreeView.Nodes.Add REG, tvwChild, REG & vbTab & BIG_AG, BIG_AG
            End If
            TreeView.Nodes.Add REG & vbTab & BIG_AG, tvwChild, REG & vbTab & BIG_AG & vbTab & RS!LITTLE_AG, RS!LITTLE_AG
            RS.MoveNext
        Wend
        RS.Close
    End Sub
    I'm using ADO, if you not, you must to do changes.
    Also if the vbTab char, could be in the data, you must use other char for the keys of the treeview nodes

  3. #3
    Member gilman's Avatar
    Join Date
    Jan 2017
    Posts
    42

    Re: how to treeview this reordset

    Try this:
    Code:
    Private Sub LoadTreeView()
        Dim REG As String
        Dim BIG_AG As String
        Dim RS As ADODB.Recordset
        Set RS = New ADODB.Recordset
        
        RS.Open "SELECT DISTINCT REG, BIG_AG, LITTLE_AG FROM tabl1 ORDER BY REG, BIG_AG, LITTLE_AG", ADOCONN, adOpenForwardOnly
        
        While Not RS.EOF
            If REG <> RS!REG Then
                REG = RS!REG
                BIG_AG = ""
                TreeView.Nodes.Add , , REG, REG
            End If
            If BIG_AG <> RS!BIG_AG Then
                BIG_AG = RS!BIG_AG
                TreeView.Nodes.Add REG, tvwChild, REG & vbTab & BIG_AG, BIG_AG
            End If
            TreeView.Nodes.Add REG & vbTab & BIG_AG, tvwChild, REG & vbTab & BIG_AG & vbTab & RS!LITTLE_AG, RS!LITTLE_AG
            RS.MoveNext
        Wend
        RS.Close
    End Sub
    I'm using ADO, if you not, you must to do changes.
    Also, if the vbTab char, could be in the data, you must use other char for the keys of the treeview nodes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width