G
Guest
Hi,
I am trying to clear my treeview when I add new items (to refresh) and It
only seems to be removing the first Parent Node, none of the children below
are being cleared.
Am I doing something wrong? The below code is based on retreiving data from
a hierarchical table:
Thanks,Dianna
Private Sub PopulateTreeView()
treeEvents.Nodes.Clear()
Dim cmd As String
cmd = "Select * From dbo.fncGetEventTree(null) ORDER BY lineage +
Ltrim(Str(node,6,0))"
Dim da As New System.Data.SqlClient.SqlDataAdapter(cmd,
ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
da.Fill(ds)
treeEvents.Nodes.Add(New TreeNode("Event Groups"))
Dim tNode As New TreeNode
tNode = treeEvents.Nodes(0)
PopulateTreeView(0, tNode)
tNode.Expand()
End Sub
Private Sub PopulateTreeView(ByVal inParentID As Integer, ByRef
inTreeNode As TreeNode)
Dim newtag As String
dv = New DataView(ds.Tables(0))
dv.RowFilter = "parent_id = " & inParentID
Dim drv As DataRowView
For Each drv In dv
Dim parentnode As TreeNode
parentnode = New TreeNode(drv.Item("event"))
inTreeNode.Nodes.Add(parentnode)
parentnode.Tag = newtag
'call the routine again to find childern of this record.
PopulateTreeView(drv.Item("event_id"), parentnode)
Next drv
End Sub
I am trying to clear my treeview when I add new items (to refresh) and It
only seems to be removing the first Parent Node, none of the children below
are being cleared.
Am I doing something wrong? The below code is based on retreiving data from
a hierarchical table:
Thanks,Dianna
Private Sub PopulateTreeView()
treeEvents.Nodes.Clear()
Dim cmd As String
cmd = "Select * From dbo.fncGetEventTree(null) ORDER BY lineage +
Ltrim(Str(node,6,0))"
Dim da As New System.Data.SqlClient.SqlDataAdapter(cmd,
ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
da.Fill(ds)
treeEvents.Nodes.Add(New TreeNode("Event Groups"))
Dim tNode As New TreeNode
tNode = treeEvents.Nodes(0)
PopulateTreeView(0, tNode)
tNode.Expand()
End Sub
Private Sub PopulateTreeView(ByVal inParentID As Integer, ByRef
inTreeNode As TreeNode)
Dim newtag As String
dv = New DataView(ds.Tables(0))
dv.RowFilter = "parent_id = " & inParentID
Dim drv As DataRowView
For Each drv In dv
Dim parentnode As TreeNode
parentnode = New TreeNode(drv.Item("event"))
inTreeNode.Nodes.Add(parentnode)
parentnode.Tag = newtag
'call the routine again to find childern of this record.
PopulateTreeView(drv.Item("event_id"), parentnode)
Next drv
End Sub