没有例子,不能测试
如下代码,试一下
’目录树的BeforeExpandNode 事件
Dim sql As String = "Select NodeID, NodeName ,NodeType FROM 表名 WHERE ParentID = " & e.Node.Name
Dim cmd As new SQLCommand
cmd.ConnectionName = 数据源 ‘如果是外部表,就加上
Dim dt As DataTable
cmd.CommandText = sql
dt = cmd.ExecuteReader()
if dt Is NoThing Then Return
e.Sender.StopRedraw()
e.Node.Nodes.Clear
Dim nd As WinForm.TreeNode
For Each dr As DataRow In dt.DataRows
nd = e.Node.Nodes.Add(dr("NodeID"),dr("NodeName"))
If dr("NodeType") = 0 Then
nd.Nodes.Add("")
End If
Next
e.Sender.ResumeRedraw()
'控件窗口的AfterLoad 事件
Dim sql As String = "Select NodeID, NodeName FROM 表名 WHERE ParentID = -1 "
Dim cmd As new SQLCommand
cmd.ConnectionName = 数据源 ‘如果是外部表,就加上
Dim dt As DataTable
cmd.CommandText = sql
dt = cmd.ExecuteReader()
if dt Is NoThing Then Return
Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1") ‘实际的控件名
Dim nd As WinForm.TreeNode
tv.StopRedraw()
For Each dr As DataRow In dt.DataRows
nd = tv.Nodes.Add(dr("NodeID"),dr("NodeName"))
nd.Nodes.Add("")
Next
tv.ResumeRedraw()
tv.Select