我有一个树视图,它从数据库加载数据以显示产品的类别和子类别。 树视图中有4个级别的类别。 我希望当用户单击某个项目以在网格中显示这些类别和子类别(所选)中的所有产品时 这是代码
FilePath = "moneyfest.mdb"
Dim CNnwind As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath & ";Persist Security Info=False") '<==== CHANGE HERE
Dim DAdtCat As New OleDbDataAdapter("SELECT * FROM Categories ", CNnwind)
Dim DAdSub1 As New OleDbDataAdapter("SELECT * FROM ProductSubCategories where ParentCategory in (select CategoryID from Categories )", CNnwind)
Dim DAdSub2 As New OleDbDataAdapter("Select * FROM ProductSubCategories2 where ParentCategory in (SELECT id FROM ProductSubCategories where id in (select CategoryID from categories ))", CNnwind)
Dim DAdSub3 As New OleDbDataAdapter("Select * FROM ProductSubCategories3 where ParentCategory in (SELECT id FROM ProductSubCategories2 where ParentCategory in (SELECT id FROM ProductSubCategories where ParentCategory in (select CategoryID from categories )))", CNnwind)
DSNWind = New DataSet()
CNnwind.Open()
DAdtCat.Fill(DSNWind, "dtCat")
DAdSub1.Fill(DSNWind, "dtSub1")
DAdSub2.Fill(DSNWind, "dtSub2")
DAdSub3.Fill(DSNWind, "dtSub3")
CNnwind.Close()
'Create a data relation object to facilitate the relationship between the Customers and Orders data tables.
DSNWind.Relations.Add("CustToOrd", DSNWind.Tables("dtCat").Columns("CategoryID"), DSNWind.Tables("dtSub1").Columns("ParentCategory"))
DSNWind.Relations.Add("OrdToDet", DSNWind.Tables("dtSub1").Columns("id"), DSNWind.Tables("dtSub2").Columns("ParentCategory"))
DSNWind.Relations.Add("OrdToDetDet", DSNWind.Tables("dtSub2").Columns("id"), DSNWind.Tables("dtSub3").Columns("ParentCategory"))
'''''''''''''''''''''''
TreeView2.Nodes.Clear()
Dim i, n As Integer
Dim parentrow As DataRow
Dim ParentTable As DataTable
ParentTable = DSNWind.Tables("dtCat")
For Each parentrow In ParentTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item(1))
TreeView2.Nodes.Add(parentnode)
''''populate child'''''
'''''''''''''''''''''''
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode()
For Each childrow In parentrow.GetChildRows("CustToOrd")
childnode = parentnode.Nodes.Add(childrow(1))
childnode.Tag = childrow("SubCategoryName")
''''populate child2''''
''''''''''''''''''''''''''
Dim childrow2 As DataRow
Dim childnode2 As TreeNode
Dim childrow3 As DataRow
Dim childnode3 As TreeNode
childnode2 = New TreeNode()
For Each childrow2 In childrow.GetChildRows("OrdToDet")
childnode2 = childnode.Nodes.Add(childrow2(1))
childnode3 = New TreeNode()
For Each childrow3 In childrow2.GetChildRows("OrdToDetDet")
childnode3 = childnode2.Nodes.Add(childrow3(1))
Next childrow3
Next childrow2
''''''''''''''''''''''''
Next childrow
'''''''''''''''
Next parentrow