以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  目录树与数据表的问题求助  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=107822)

--  作者:fytea
--  发布时间:2017/10/10 23:27:00
--  目录树与数据表的问题求助

CaseStudy目录下的文件:目录树与数据表.Table中

“增加子节点”按钮的Click事件代码:

Dim tr As WinForm.TreeView
Dim
nd As WinForm.TreeNode
tr = e.Form.Controls(
"TreeView1")
nd = tr.SelectedNode

If
nd IsNot Nothing Then
   
If nd.Level = 2 Then
        MessageBox.Show(
"最多允许三层节点!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Else
       
Dim dr As DataRow = DataTables("表A").AddNew
        If
nd.Level = 0
Then
            dr(
"大类") = nd.Text
            dr(
"二类") = "新节点"
       
ElseIf nd.Level = 1
            dr(
"大类") = nd.ParentNode.Text
            dr(
"二类") = nd.text
            dr(
"三类") = "新节点"
       
End If
        nd = nd.Nodes.Add(
"新节点")
        tr.SelectedNode = nd
        tr.
Select()
        tr.BeginEdit()

    End
If
End
If

我想改成,每增加一个新节点,名称不是“新节点”,而是对应的“二类”、“三类”

老师:如何做?


--  作者:有点甜
--  发布时间:2017/10/11 9:42:00
--  

Dim tr As WinForm.TreeView
Dim nd As WinForm.TreeNode
tr = e.Form.Controls("TreeView1")
nd = tr.SelectedNode
If nd IsNot Nothing Then
    If nd.Level = 2 Then
        MessageBox.Show("最多允许三层节点!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Else
        Dim dr As DataRow = DataTables("表A").AddNew
        If nd.Level = 0 Then
            dr("大类") = nd.Text
            dr("二类") = "二类"

            nd = nd.Nodes.Add("二类")
        ElseIf nd.Level = 1
            dr("大类") = nd.ParentNode.Text
            dr("二类") = nd.text
            dr("三类") = "三类"

            nd = nd.Nodes.Add("三类")
        End If
        tr.SelectedNode = nd
        tr.Select()
        tr.BeginEdit()
    End If
End If