这样试试
Dim tr As WinForm.TreeView
Dim nd As WinForm.TreeNode
tr = Forms("参数设置").Controls("TreeView1")
Dim i1,i2 AS Integer
Dim str1,str2 AS String
Dim txtBox As String = e.Form.Controls("TextBox1").Value
If txtBox = "" Then
MessageBox.Show("请输入要增加节点的名称!","提示")
Return
End If
Dim 新行1 As DataRow
新行1 = DataTables("单位树").AddNew()
If vars("str100") = "根" Then
i1 = DataTables("单位树").Compute("count(节点)","节点 = 0") + 1
str1 = format(i1,"00")
nd = Tr.Nodes.Add(str1,txtBox)
tr.SelectedNode = nd
新行1("标题id") = str1
新行1("标题") = txtbox
新行1("节点") = 0
新行1("节点位") = i1
txtBox = ""
Else
nd=tr.SelectedNode
str1 = nd.Name
Dim dr As DataRow = DataTables("单位树").Find("标题 = '" & nd.Text & "'")
i2=nd.Level+1
i1 = DataTables("单位树").Compute("count(节点)","标题id like '" & str1 & "'") + 1
str2 = format(i1,"00")
nd.Nodes.Add( str1 & str2 ,txtBox)
新行1("标题id") = dr("标题id") & str2
新行1("标题") = txtbox
新行1("节点") = i2
新行1("节点位") = i1
txtBox = ""
nd.Expand()
End If
If e.Form.Controls("CheckBox1").Checked = True Then
e.Form.Controls("TextBox1").Select()
Else
e.form.Close()
End If