从3个表配置三级树视图时出现问题

时间:2019-07-11 12:08:10

标签: vb.net

I've added the upper image of the view as the lower one was missing info! So if a mod could delete the lower image! or replace it with the upper one!  首次尝试使用树视图。我一直在寻找示例,但没有找到任何符合我想要的视觉基础示例。这段代码来自ASP.net,我正努力上班!

我必须从3个表中显示treeview,并且据我所知,它更容易实现 将它们放在一起,因此我创建了一个具有联接的视图,该联接具有我需要的所有数据!

这是到目前为止的代码!

 Private Sub GetTreeViewItems()

    Dim con As New SqlConnection(sDatahubConnString)
    Dim DS As New DataSet()
    Dim dr As SqlDataReader
    Dim NN As TreeNode
    Dim DA As New SqlDataAdapter("task_tree", con)
    Dim level1datarow As DataRow
    con = New SqlConnection(sDatahubConnString)
    Dim parentTreeNode As New TreeNode
    Dim Childrows As DataRelation
    DA.Fill(DS)

    Childrows = DS.Relations.Add("ChildRows", DS.Tables(0).Columns("prime_ID"), DS.Tables(0).Columns("primetsk_ID"))
    For Each level1datarow In DS.Tables(0).Rows
        level1datarow = DS.Tables(0).NewRow
    Next
    If String.IsNullOrEmpty(level1datarow("Prime_ID").ToString()) Then

        parentTreeNode = New TreeNode()
        parentTreeNode.Text = level1datarow("Prime_ID").ToString()
        'parentTreeNode.NavigateUrl = level1datarow["NavigateURL"].ToString()
        GetChildRows(level1datarow, parentTreeNode)
        TreeView1.Nodes.Add(parentTreeNode)
    End If

        NN = TreeView1.Nodes.Add(dr("Prime_ID"), dr("task_name"))

    Loop
    dr.Close()


End Sub

Private Sub GetChildRows(dataRow As DataRow, treeNode As TreeNode)
    Dim childrow, row As DataRow
    Dim childtreenode As TreeNode
    childrow = **dataRow.GetChildRows("ChildRows")** 'here I get type DATAROW() connot be converted to DATAROW
    For Each row In **childrow** ' here I get type datarow is not a collection of type

        childtreenode = New TreeNode()
        childtreenode.Text = row("task_name").ToString()
        **treeNode.Childnodes**.Add(childtreenode) ' here I get childnodes is not a member of tree node

        If (row.GetChildRows("ChildRows").Length > 0) Then

            GetChildRows(row, childtreenode)
        End If

    Next

End Sub

这里是风景!

This is the view which is a join of the 3 tables

我不希望有人为我完成代码,但现在我陷入困境,需要指出正确的方向1

谢谢

Pete

0 个答案:

没有答案