Results 1 to 2 of 2

Thread: Populating Treeview with two tables

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Populating Treeview with two tables

    I am trying to add information from two tables on a treeview. I know I can do this with a relationship but I would rather not. Parent table contains the Groups and tblContacts contain the name. With the code listed below it adds the groups as it is desiged to do but it adds every name to each group regardless of the group the name belongs to.

    I have just started to program. And would greatly appreciate any help.





    Sub PopulateTreeView()
    TreeView1.Nodes.Clear()

    Dim PRow As DataRow
    Dim ParentTable As DataTable
    Dim parentnode As TreeNode
    ParentTable = ds.Tables(1)

    For Each PRow In ParentTable.Rows

    parentnode = New TreeNode(PRow.Item(1))
    TreeView1.Nodes.Add(parentnode)
    Next PRow

    For Each parentnode In TreeView1.Nodes
    Dim strg As String
    strg = parentnode.Text
    LV1.Items.Add(strg)
    Next parentnode


    For Each parentnode In TreeView1.Nodes
    Dim CRow As DataRow
    Dim tempDataView As New DataView
    Dim strg As String

    tempDataView.Table = ds.Tables("tblContacts")
    strg = parentnode.Text
    tempDataView.RowFilter = "Group like '" & strg & "*'"
    TreeView1.SelectedNode = parentnode

    For Each CRow In tempDataView.Table.Rows
    Dim childnode As New TreeNode
    childnode = New TreeNode(CRow.Item(2))
    Me.TreeView1.SelectedNode.Nodes.Add(childnode)
    Next CRow
    tempDataView.Dispose()
    Next parentnode

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Re: Populating Treeview with two tables

    Perhaps my noob code is confusing:

    I have two tables
    table 1 - Groups
    Friends
    Family
    Business

    table 2 - Contacts
    Jan Doe - Friends
    Joe Smo - Family
    Elect Co - Business


    I am trying to get a treeview with roots - Friends, Family, Business and then add the contacts to the corresponding groups

    -Friends
    Jan Doe
    -Family
    Joe Smo
    -Business
    Elect Co


    As it is now its doing:
    -Friends
    Jan Doe
    Joe Smo
    Elect Co
    -Family
    Jan Doe
    Joe Smo
    Elect Co
    -Business
    Jan Doe
    Joe Smo
    Elect Co


    Please help and at leat point me in the right direction

Posting Permissions

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



Click Here to Expand Forum to Full Width