Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - get child node of selected parent node

Reply
 
Old 08-10-2009   #1 (permalink)
jcoon


 
 

get child node of selected parent node

All,

I've tried working on this this before with no luck. I've looked all over
and can't seem to find a sample that I can redo (understand) to test with my
sample.
I've created a treeview with nodes from the sample below. I'd like to be
able to use the TreeView1_AfterSelect to retrieve the child node text values
and tag values.
to place in message box or userform labels.

If I select parent node Visual-Runway-A in the treeview I'd like to collect
the text values and tag values for all nodes(0)...under the parent
Visual-Runway-A. )
Pretty new to dot net.

Thanks for all your help.
John



TreeView1.Nodes.Add("Visual-Runway-A")
TreeView1.Nodes(0).Tag = ("Visual-Runway-A")
TreeView1.Nodes(0).Nodes.Add("Inner Width").Tag = "250"
TreeView1.Nodes(0).Nodes.Add("Outer Width").Tag = "1250"
TreeView1.Nodes(0).Nodes.Add("Surface Length").Tag = "5000"
TreeView1.Nodes(0).Nodes.Add("Slope").Tag = "20:1"
TreeView1.Nodes(0).Nodes.Add("Radius").Tag = "5000"

TreeView1.Nodes.Add("Visual-Runway-B")
TreeView1.Nodes(1).Tag = ("Visual-Runway-B")
TreeView1.Nodes(1).Nodes.Add("Inner Width").Tag = "500"
TreeView1.Nodes(1).Nodes.Add("Outer Width").Tag = "1500"
TreeView1.Nodes(1).Nodes.Add("Surface Length").Tag = "5000"
TreeView1.Nodes(1).Nodes.Add("Slope").Tag = "20:1"
TreeView1.Nodes(1).Nodes.Add("Radius").Tag = "5000"

continues.......to nodes(5) not shown


My System SpecsSystem Spec
Old 08-10-2009   #2 (permalink)
Family Tree Mike


 
 

Re: get child node of selected parent node

jcoon wrote:
Quote:

> All,
>
> I've tried working on this this before with no luck. I've looked all
> over and can't seem to find a sample that I can redo (understand) to
> test with my sample.
> I've created a treeview with nodes from the sample below. I'd like to be
> able to use the TreeView1_AfterSelect to retrieve the child node text
> values and tag values.
> to place in message box or userform labels.
>
> If I select parent node Visual-Runway-A in the treeview I'd like to
> collect the text values and tag values for all nodes(0)...under the
> parent Visual-Runway-A. )
> Pretty new to dot net.
>
> Thanks for all your help.
> John
>
>
>
> TreeView1.Nodes.Add("Visual-Runway-A")
> TreeView1.Nodes(0).Tag = ("Visual-Runway-A")
> TreeView1.Nodes(0).Nodes.Add("Inner Width").Tag = "250"
> TreeView1.Nodes(0).Nodes.Add("Outer Width").Tag = "1250"
> TreeView1.Nodes(0).Nodes.Add("Surface Length").Tag = "5000"
> TreeView1.Nodes(0).Nodes.Add("Slope").Tag = "20:1"
> TreeView1.Nodes(0).Nodes.Add("Radius").Tag = "5000"
>
> TreeView1.Nodes.Add("Visual-Runway-B")
> TreeView1.Nodes(1).Tag = ("Visual-Runway-B")
> TreeView1.Nodes(1).Nodes.Add("Inner Width").Tag = "500"
> TreeView1.Nodes(1).Nodes.Add("Outer Width").Tag = "1500"
> TreeView1.Nodes(1).Nodes.Add("Surface Length").Tag = "5000"
> TreeView1.Nodes(1).Nodes.Add("Slope").Tag = "20:1"
> TreeView1.Nodes(1).Nodes.Add("Radius").Tag = "5000"
>
> continues.......to nodes(5) not shown
It appears you want a VB example, so try this:

Private Sub TreeView1_AfterSelect _
(ByVal sender As Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles TreeView1.AfterSelect

Dim tn As TreeNode = e.Node
Dim d As New Dictionary(Of String, Object)

For Each child As TreeNode In tn.Nodes
d.Add(child.Text, child.Tag)
Next

' do something with the dictionary
End Sub

e.Node contains the node selected, and the Nodes property contains the
children of that node.

--
Mike
My System SpecsSystem Spec
Old 08-11-2009   #3 (permalink)
jcoon


 
 

Re: get child node of selected parent node

Mike,

Thank you, I was able to add your sample and retrieved the child.text and
child.tag under the selected parent.
would I have to do another for each loop to to get the remaining child text
and tags under the parent.

in this sample if I select the parent node Visual-Runway-A
I'd like to get all child text and tag so I can read them into a messagebox

any hints or links are welcome.

have a great day
John


TreeView1.Nodes.Add("Visual-Runway-A")
TreeView1.Nodes(0).Tag = ("Visual-Runway-A")
TreeView1.Nodes(0).Nodes.Add("Inner Width").Tag = "250"
TreeView1.Nodes(0).Nodes.Add("Outer Width").Tag = "1250"
TreeView1.Nodes(0).Nodes.Add("Surface Length").Tag = "5000"
TreeView1.Nodes(0).Nodes.Add("Slope").Tag = "20:1"
TreeView1.Nodes(0).Nodes.Add("Radius").Tag = "5000"

TreeView1.Nodes.Add("Visual-Runway-B")
TreeView1.Nodes(1).Tag = ("Visual-Runway-B")
TreeView1.Nodes(1).Nodes.Add("Inner Width").Tag = "500"
TreeView1.Nodes(1).Nodes.Add("Outer Width").Tag = "1500"
TreeView1.Nodes(1).Nodes.Add("Surface Length").Tag = "5000"
TreeView1.Nodes(1).Nodes.Add("Slope").Tag = "20:1"
TreeView1.Nodes(1).Nodes.Add("Radius").Tag = "5000"




"Family Tree Mike" <FamilyTreeMike@xxxxxx> wrote in message
news:%23M6CPhiGKHA.3392@xxxxxx
Quote:

> jcoon wrote:
Quote:

>> All,
>>
>> I've tried working on this this before with no luck. I've looked all over
>> and can't seem to find a sample that I can redo (understand) to test with
>> my sample.
>> I've created a treeview with nodes from the sample below. I'd like to be
>> able to use the TreeView1_AfterSelect to retrieve the child node text
>> values and tag values.
>> to place in message box or userform labels.
>>
>> If I select parent node Visual-Runway-A in the treeview I'd like to
>> collect the text values and tag values for all nodes(0)...under the
>> parent Visual-Runway-A. )
>> Pretty new to dot net.
>>
>> Thanks for all your help.
>> John
>>
>>
>>
>> TreeView1.Nodes.Add("Visual-Runway-A")
>> TreeView1.Nodes(0).Tag = ("Visual-Runway-A")
>> TreeView1.Nodes(0).Nodes.Add("Inner Width").Tag = "250"
>> TreeView1.Nodes(0).Nodes.Add("Outer Width").Tag = "1250"
>> TreeView1.Nodes(0).Nodes.Add("Surface Length").Tag = "5000"
>> TreeView1.Nodes(0).Nodes.Add("Slope").Tag = "20:1"
>> TreeView1.Nodes(0).Nodes.Add("Radius").Tag = "5000"
>>
>> TreeView1.Nodes.Add("Visual-Runway-B")
>> TreeView1.Nodes(1).Tag = ("Visual-Runway-B")
>> TreeView1.Nodes(1).Nodes.Add("Inner Width").Tag = "500"
>> TreeView1.Nodes(1).Nodes.Add("Outer Width").Tag = "1500"
>> TreeView1.Nodes(1).Nodes.Add("Surface Length").Tag = "5000"
>> TreeView1.Nodes(1).Nodes.Add("Slope").Tag = "20:1"
>> TreeView1.Nodes(1).Nodes.Add("Radius").Tag = "5000"
>>
>> continues.......to nodes(5) not shown
>
> It appears you want a VB example, so try this:
>
> Private Sub TreeView1_AfterSelect _
> (ByVal sender As Object, _
> ByVal e As System.Windows.Forms.TreeViewEventArgs) _
> Handles TreeView1.AfterSelect
>
> Dim tn As TreeNode = e.Node
> Dim d As New Dictionary(Of String, Object)
>
> For Each child As TreeNode In tn.Nodes
> d.Add(child.Text, child.Tag)
> Next
>
> ' do something with the dictionary
> End Sub
>
> e.Node contains the node selected, and the Nodes property contains the
> children of that node.
>
> --
> Mike
My System SpecsSystem Spec
Old 08-11-2009   #4 (permalink)
Family Tree Mike


 
 

Re: get child node of selected parent node

jcoon wrote:
Quote:

> Mike,
>
> Thank you, I was able to add your sample and retrieved the child.text
> and child.tag under the selected parent.
> would I have to do another for each loop to to get the remaining child
> text and tags under the parent.
>
> in this sample if I select the parent node Visual-Runway-A
> I'd like to get all child text and tag so I can read them into a messagebox
>
> any hints or links are welcome.
>
> have a great day
> John
>
>
> TreeView1.Nodes.Add("Visual-Runway-A")
> TreeView1.Nodes(0).Tag = ("Visual-Runway-A")
> TreeView1.Nodes(0).Nodes.Add("Inner Width").Tag = "250"
> TreeView1.Nodes(0).Nodes.Add("Outer Width").Tag = "1250"
> TreeView1.Nodes(0).Nodes.Add("Surface Length").Tag = "5000"
> TreeView1.Nodes(0).Nodes.Add("Slope").Tag = "20:1"
> TreeView1.Nodes(0).Nodes.Add("Radius").Tag = "5000"
>
The code I gave should have given a dictionary with five elements in it.
The keys should have been "Inner Width", "Outer Width", "Surface
Length", "Slope" and "Radius". The values for the keys respectively,
should have been "250", "1250", "5000", "20:1" and "5000".

Are you not getting this from the code when you select "Visual-Runaway-A"?

--
Mike
My System SpecsSystem Spec
Old 08-12-2009   #5 (permalink)
jcoon


 
 

Re: get child node of selected parent node


Mike,

Sorry, I now see the dictionary in the locals window under d and it is
cycling thru
the items under the selected parent node. I've never worked with a
dictionary or treeview before, I was looking in the wrong location.

In debug I can see the d.item keys and vlaue string as it iterates thru and
populates the dictionary, but when I try to get the values I don't see how to
get the d.tem key and d.item value string as shown in the locals window.

I know this is a struggle working with someone who doesn't understand these
newer control items but in time I will learn how these tools work, the old me
would of just made and if Visual-Runway-A was selected then form label
1,2,3... are equal to what I already types in the tree text, I'm trying to
change that.

Have a great day,
John











"Family Tree Mike" wrote:
Quote:

> jcoon wrote:
Quote:

> > Mike,
> >
> > Thank you, I was able to add your sample and retrieved the child.text
> > and child.tag under the selected parent.
> > would I have to do another for each loop to to get the remaining child
> > text and tags under the parent.
> >
> > in this sample if I select the parent node Visual-Runway-A
> > I'd like to get all child text and tag so I can read them into a messagebox
> >
> > any hints or links are welcome.
> >
> > have a great day
> > John
> >
> >
> > TreeView1.Nodes.Add("Visual-Runway-A")
> > TreeView1.Nodes(0).Tag = ("Visual-Runway-A")
> > TreeView1.Nodes(0).Nodes.Add("Inner Width").Tag = "250"
> > TreeView1.Nodes(0).Nodes.Add("Outer Width").Tag = "1250"
> > TreeView1.Nodes(0).Nodes.Add("Surface Length").Tag = "5000"
> > TreeView1.Nodes(0).Nodes.Add("Slope").Tag = "20:1"
> > TreeView1.Nodes(0).Nodes.Add("Radius").Tag = "5000"
> >
>
> The code I gave should have given a dictionary with five elements in it.
> The keys should have been "Inner Width", "Outer Width", "Surface
> Length", "Slope" and "Radius". The values for the keys respectively,
> should have been "250", "1250", "5000", "20:1" and "5000".
>
> Are you not getting this from the code when you select "Visual-Runaway-A"?
>
> --
> Mike
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Remove XML element from a node PowerShell
XML node passed to function PowerShell
Removing an XML node .NET General
How to delete a DFS node using Powershell PowerShell
Counting a particular node in a XML file PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46