有一段生成目录树的代码,要求在数据汇总表增加数据时,能够动态更新目录树,如何来实现这个效果,请各位老师帮助指教,谢谢!
在数据汇总窗口的AfterLoad事件中的代码:
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C ‘数据源
cmd.CommandText = "SELECT DISTINCT 年月,单位 From {数据汇总}"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt, "年月|单位","","年月 DESC,单位")
trv.Nodes.Insert("加载所有数据",0)
在数据汇总窗口TreeView1目录树的NodeMouseDoubleClick事件中的代码:
Dim Filter As String
If e.Node.Text = "加载所有数据" Then
Filter = ""
Else
Dim Value() As String
Value = e.Node.FullPath.Split("\")
Select Case e.Node.Level
Case 0
Filter ="[年月] = '" & Value(0) & "'"
Case 1
Filter ="[年月] = '" & Value(0) & "' And [单位] = '" & Value(1) & "'"
End Select
End If
DataTables("数据汇总").LoadFilter = Filter
DataTables("数据汇总").Load()
[此贴子已经被作者于2012-6-21 9:21:35编辑过]