编辑目录树之二
本节的内容,可以参考CaseStudy目录下的文件:目录树与数据表.Table
本节的任务和上一节类似,不过目录树根据表生成,而且:
1、在目录树重命名节点,能够自动修改表中的相关数据。
2、在目录树删除节点,能够自动删除表中对应的行。
3、在目录树增加节点,能够自动在表中增加一行。
设计步骤:
1、首先设计一个上图所示的窗口。
2、窗口的AfterLoad事件代码为:
Dim
tr As WinForm.TreeView = e.Form.Controls("TreeView1")3、“重命名”按钮的Click事件代码:
Dim
tr As WinForm.TreeView4、“增加根节点”按钮的Click事件代码:
Dim
dr As DataRow = DataTables("表A").AddNew5、“增加子节点”按钮的Click事件代码:
Dim
tr As WinForm.TreeView6、“删除”按钮的Click事件代码:
Dim
tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode =
tr.SelectedNode
If nd IsNot
Nothing Then
Dim pth() As
String = nd.FullPath.Split("\")
Select Case nd.Level
Case 0
DataTables("表A").DeleteFor("大类
= '" & pth(0)
& "'")
Case 1
DataTables("表A").DeleteFor("大类
= '" & pth(0)
& "' And
二类
= '" & pth(1)
& "'")
Case 2
DataTables("表A").DeleteFor("大类
= '" & pth(0)
& "' And
二类
= '" & pth(1)
& "' And
三类
= '" & pth(2)
& "'")
End Select
nd.Delete()
End If
tr.Select()
7、目录树AfterEditNode事件代码:
If
e.NewText
=
""
Then
e.Cancel
= True
Return
End If
Dim
pth()
As
String
=
e.Node.FullPath.Split("\")
Select Case
e.node.Level
Case
0
DataTables("表A").ReplaceFor("大类",e.NewText,"大类
= '"
&
pth(0)
&
"'")
Case
1
DataTables("表A").ReplaceFor("二类",e.NewText,"大类
= '"
&
pth(0)
&
"' And
二类
= '"
&
pth(1)
&
"'")
Case
2
DataTables("表A").ReplaceFor("三类",e.NewText,"大类
= '"
&
pth(0)
&
"' And
二类
= '"
&
pth(1)
&
"' And
三类
= '"
&
pth(2)
&
"'")
End Select
e.Node.Name
=
e.NewText