|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Treeview Nodes.ClearI 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
Show quote
"Dianna" <Dia***@discussions.microsoft.com> wrote in message I've tried to replicate your problem in test Windows VB apps in both Visual news:D4C973D4-721A-4DC8-8A40-AE34E9A5CF1A@microsoft.com... > 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 > > Studio .NET 2003 and in Visual Studio 2005. The Clear() method clears all nodes. As I may have made invalid assumptions about the software you are using, its edition and version, and I guessed at the project type and template, please supply that information. I may be belaboring the obvious here, but have you stepped through your subprocedure in the debugger to see the state of the Treeview object just after the Clear() executes? -- Peter [MVP Visual Developer] Jack of all trades, master of none. What I am noticing is that when I do
Treeview.Nodes.clear it removes the top parent to the tree ("Event Groups") Everything else under the parent (treeEvents.Nodes(0).Nodes) - the children stays there. Even treeview.Nodes.count says 0. However, treeEvents.Nodes(0).Nodes.count says 17..? It looks like I can clear the children by doing treeEvents.Nodes(0).Nodes.Clear, but this is being built dynamically using a hierarchical table. The user can have as many children as he wants. So the trick will be to find out how many levels in the tree. I think, I'm guessing. Show quote "pvdg42" wrote: > > "Dianna" <Dia***@discussions.microsoft.com> wrote in message > news:D4C973D4-721A-4DC8-8A40-AE34E9A5CF1A@microsoft.com... > > 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've tried to replicate your problem in test Windows VB apps in both Visual > Studio .NET 2003 and in Visual Studio 2005. The Clear() method clears all > nodes. > As I may have made invalid assumptions about the software you are using, its > edition and version, and I guessed at the project type and template, please > supply that information. > I may be belaboring the obvious here, but have you stepped through your > subprocedure in the debugger to see the state of the Treeview object just > after the Clear() executes? > > -- > Peter [MVP Visual Developer] > Jack of all trades, master of none. > > > Hi Peter,
Oh Well, this was kind of dumb, but it was not the treeview. It was my dataset. Everytime I called the routine it appened to it. Thanks. Dianna Show quote "pvdg42" wrote: > > "Dianna" <Dia***@discussions.microsoft.com> wrote in message > news:D4C973D4-721A-4DC8-8A40-AE34E9A5CF1A@microsoft.com... > > 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've tried to replicate your problem in test Windows VB apps in both Visual > Studio .NET 2003 and in Visual Studio 2005. The Clear() method clears all > nodes. > As I may have made invalid assumptions about the software you are using, its > edition and version, and I guessed at the project type and template, please > supply that information. > I may be belaboring the obvious here, but have you stepped through your > subprocedure in the debugger to see the state of the Treeview object just > after the Clear() executes? > > -- > Peter [MVP Visual Developer] > Jack of all trades, master of none. > > > "Dianna" <Dia***@discussions.microsoft.com> wrote in message All's well that ends well :)news:247A0EAB-0128-476B-8058-214B29F6B2EF@microsoft.com... > Hi Peter, > > Oh Well, this was kind of dumb, but it was not the treeview. It was my > dataset. Everytime I called the routine it appened to it. > > Thanks. > > Dianna > |
|||||||||||||||||||||||