Problem with Treeview
Hi,
I have a table which has 3 columns. This is how my table looks with the data
id-->parent-->name
1-->0-->test
2-->0-->test1
3-->0-->test2
4-->1-->tester
now i want to display this data in a treeview control. I used the code example but it dint help me.I hope somebody can help me. Please its urgent.
i want the treeview to be displayed like this:
-test
|-tester(this is a child of test)
|test1
|test2
This is what i tried
Dim strConn As String = "server=.;database=Northwind;integrated security=true;"
Dim objConn As New SqlConnection(strConn)
Dim objDS As New DataSet
Dim daSuppliers As New SqlDataAdapter("SELECT * FROM tree where parent=0", objConn)
Dim daProducts As New SqlDataAdapter("SELECT * FROM tree where parent=id", objConn)
daSuppliers.Fill(objDS, "dtSuppliers")
daProducts.Fill(objDS, "dtProducts")
objConn.Close()
objDS.Relations.Add("SuppToProd", _
objDS.Tables("dtSuppliers").Columns("id"), _
objDS.Tables("dtProducts").Columns("parent"))
Dim nodeSupp, nodeProd As TreeNode
Dim rowSupp, rowProd As DataRow
For Each rowSupp In objDS.Tables("dtSuppliers").Rows
nodeSupp = New TreeNode
nodeSupp.Text = rowSupp("name")
nodeSupp.ID = rowSupp("id")
TreeView1.Nodes.Add(nodeSupp)
For Each rowProd In rowSupp.GetChildRows("SuppToProd")
nodeProd = New TreeNode
nodeProd.Text = rowProd("name")
nodeProd.ID = rowProd("id")
nodeSupp.Nodes.Add(nodeProd)
Next
Next
'clean up
objDS.Dispose()
daSuppliers.Dispose()
daProducts.Dispose()
objConn.Close()
objConn.Dispose()
Can somebody please help with or guide me as to where or what i am doing wrong or what i am missing.
Thanks in advance.
Regards
|