第一步: 菜单右键命令: 这一块运行正常。
Case "增加"
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode = tr.SelectedNode
Dim id As Integer = nd.index
CurrentTable.AddNew
If nd.ParentNode Is Nothing Then
nd = tr.Nodes.add("新节点")
tr.SelectedNode = nd
CurrentTable.Current ("笔记分类") = nd.name
Else
nd = nd.ParentNode.Nodes.add("新节点")
tr.SelectedNode = nd
tr.Select
tr.BeginEdit
Select Case nd.Level
Case 1
CurrentTable.Current ("笔记分类") = nd.ParentNode.name
CurrentTable.Current ("笔记子项") = nd.name
Case 2
CurrentTable.Current ("笔记分类") = nd.ParentNode.ParentNode.name
CurrentTable.Current ("笔记子项") = nd.ParentNode.name
CurrentTable.Current ("子项实例") = nd.name
End Select
End If
tr.BuildTree("学习笔记", "笔记分类|笔记子项|子项实例")
tr.Nodes.Insert("显示所有行", 0)
For Each nd1 As WinForm.TreeNode In tr.AllNodes
If nd1.name = "新节点" Then
tr.SelectedNode = nd1
nd1.Expand
tr.Select
tr.BeginEdit
End If
Next
第二步:目录树,aftereditnode事件 总是目录节点改名后,表字段不能同步更改。
e.Node.Name = e.Node.Text
If CurrentTable.Current.Locked = True Then
MessageBox.Show ("已锁定,禁止编辑!")
Return
End If
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim dr As DataRow = e.Node.DataRow
If e.Node.ParentNode Is Nothing Then
tr.SelectedNode = e.Node
dr("笔记分类") = e.Node.Text
Else
If e.Node.Level = 1 Then
tr.SelectedNode = e.Node
dr("笔记分类") = e.Node.ParentNode.Text
dr("笔记子项") = e.Node.Text
ElseIf e.Node.Level = 2 Then
dr("笔记分类") = e.Node.ParentNode.ParentNode.Text
dr("笔记子项") = e.Node.ParentNode.Text
dr("子项实例") = e.NewText
End If
End If