PC Review


Reply
Thread Tools Rate Thread

adding a node to a parent node in a tree view

 
 
Brian Henry
Guest
Posts: n/a
 
      17th Jan 2004
If i already have a tree view created, and want to add another new node to
it, how would i do so? Is there a way to throught tags or anything? like i
have this

RootNode
|
+-- Child 1
+-- Child 2

and i want to add a child node to child 1 how would i refrence it and add a
new one to it after the list was already made? thanks (each node is getting
a name and a tag during the initial creation)


 
Reply With Quote
 
 
 
 
IbrahimMalluf
Guest
Posts: n/a
 
      17th Jan 2004
Hello Brian

To add children to a node you have to get a reference to the node you want
to add children to then use the Nodes.Add methof of the node. The code
below adds three levels of nodes using for-next loops. It should provide
youy with a demonstration of how to populate a treeview


Dim TopNode As TreeNode

Dim SecondNode As TreeNode

Dim ThirdNode As TreeNode

With Me.TreeView1

For MyCount1 As Integer = 0 To 5

'adds top level node

TopNode = .Nodes.Add("TopNode" & MyCount1)

For MyCount2 As Integer = 0 To 5

'adds second level node

SecondNode = TopNode.Nodes.Add("SecondLevelNode" & MyCount2)

For MyCount3 As Integer = 0 To 5

'adds third level node

SecondNode.Nodes.Add("ThirdLevelNode" & MyCount3)

Next

Next

Next

End With




--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:(E-Mail Removed)...
> If i already have a tree view created, and want to add another new node to
> it, how would i do so? Is there a way to throught tags or anything? like i
> have this
>
> RootNode
> |
> +-- Child 1
> +-- Child 2
>
> and i want to add a child node to child 1 how would i refrence it and add

a
> new one to it after the list was already made? thanks (each node is

getting
> a name and a tag during the initial creation)
>
>



 
Reply With Quote
 
Brian Henry
Guest
Posts: n/a
 
      17th Jan 2004
yes that I know, but if I am dynamically adding new nodes after it has been
initially built how would i find a node in the tree that I am looking for
and preform an add to its node colletion?


"IbrahimMalluf" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Brian
>
> To add children to a node you have to get a reference to the node you want
> to add children to then use the Nodes.Add methof of the node. The code
> below adds three levels of nodes using for-next loops. It should provide
> youy with a demonstration of how to populate a treeview
>
>
> Dim TopNode As TreeNode
>
> Dim SecondNode As TreeNode
>
> Dim ThirdNode As TreeNode
>
> With Me.TreeView1
>
> For MyCount1 As Integer = 0 To 5
>
> 'adds top level node
>
> TopNode = .Nodes.Add("TopNode" & MyCount1)
>
> For MyCount2 As Integer = 0 To 5
>
> 'adds second level node
>
> SecondNode = TopNode.Nodes.Add("SecondLevelNode" & MyCount2)
>
> For MyCount3 As Integer = 0 To 5
>
> 'adds third level node
>
> SecondNode.Nodes.Add("ThirdLevelNode" & MyCount3)
>
> Next
>
> Next
>
> Next
>
> End With
>
>
>
>
> --
> Ibrahim Malluf
> http://www.malluf.com
> ==============================================
> MCS Data Services Code Generator
> http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
> ==============================================
> Pocket PC Return On Investment Calculator
> Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx
>
> "Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
> news:(E-Mail Removed)...
> > If i already have a tree view created, and want to add another new node

to
> > it, how would i do so? Is there a way to throught tags or anything? like

i
> > have this
> >
> > RootNode
> > |
> > +-- Child 1
> > +-- Child 2
> >
> > and i want to add a child node to child 1 how would i refrence it and

add
> a
> > new one to it after the list was already made? thanks (each node is

> getting
> > a name and a tag during the initial creation)
> >
> >

>
>



 
Reply With Quote
 
Webster
Guest
Posts: n/a
 
      18th Jan 2004
You can recursively iterate through the nodes (starting at the root), and
then just find that matching tag or text or whatever.

node find (string tofind, node root)
if root has children
return find(tofind, root.nodes(0))
else
if root.tag = tofind then
return root
end if
end if
end function

something like that pseudo code.

--
Regards,
Webster

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:(E-Mail Removed)...
> If i already have a tree view created, and want to add another new node to
> it, how would i do so? Is there a way to throught tags or anything? like i
> have this
>
> RootNode
> |
> +-- Child 1
> +-- Child 2
>
> and i want to add a child node to child 1 how would i refrence it and add

a
> new one to it after the list was already made? thanks (each node is

getting
> a name and a tag during the initial creation)
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get child node of selected parent node jcoon Microsoft Dot NET 9 13th Aug 2009 01:59 PM
When Child node check parent node has to be checked intreeview asp.net 2.0 Janarthanan Lakshmanan Microsoft C# .NET 0 30th Aug 2007 05:06 PM
Parent-Child Node Check Box Interation in Tree-view Bob Microsoft C# .NET 2 17th Aug 2007 03:42 PM
Traversing from selecting node to parent node Abdul H S via DotNetMonster.com Microsoft C# .NET 1 5th Sep 2005 10:57 PM
strange problem adding child node to a parent node =?Utf-8?B?TXJOb2JvZHk=?= Microsoft C# .NET 3 11th Jan 2005 08:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:07 AM.