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