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 = 4 Then MessageBox.Show("最多允许5层节点!","提示",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("三类") = "新节点" ElseIf nd.level = 2 Dim ary() As String = nd.fullPath.split("\") dr("大类") = ary(0) dr("二类") = ary(1) dr("三类") = ary(2) dr("4类") = "新节点" ElseIf nd.level = 3 Dim ary() As String = nd.fullPath.split("\") dr("大类") = ary(0) dr("二类") = ary(1) dr("三类") = ary(2) dr("4类") = ary(3) dr("5类") = "新节点" End If nd = nd.Nodes.Add("新节点") tr.SelectedNode = nd tr.Select() tr.BeginEdit() End If End If
|