473,699 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parent and Child for a Treeview.

the code below dows not let me get the parent child view... all the nodes are
show in one line only...

also i need them to be collasped ...

Thanks ..


Private Sub GetTree()
Dim objNode As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
objNode = New TreeNode
objNode.Text = TextBox1.Text
TreeView1.Nodes .Add(objNode)

For Each objProject In objSession.Proj ects

objNode = TreeView1.Nodes .Add(objProject .Name)

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

objNode = TreeView1.Nodes .Add(objBaselin e.Name)

If objBaseline.Nam e = "Default View" Then
objNode.Text = "Current Baseline"
Else
objNode.Text = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so user
can cancel

objNode = TreeView1.Nodes .Add(objReqType .Name)

Next objReqType
End If
Next objBaseline
Next objProject
objNode = Nothing
Exit Sub

End Sub
Nov 21 '05 #1
7 3766
Yes, you have effectively built a flat tree. At each nesting level, you
need to add the nodes further down the branches to their parent - so, simply
store the parent in "root", "firstlevel ", "secondleve l" etc.....
Try this....


Private Sub GetTree()
Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

For Each objProject In objSession.Proj ects

firstLevel = root.Nodes.Add( objProject.Name )

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

secondLevel= firstLevel.Node s.Add(objBaseli ne.Name)

If objBaseline.Nam e = "Default View" Then
secondLevel.Tex t = "Current Baseline"
Else
secondLevel.Tex t = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so user
can cancel

thirdLevel = secondLevel.Nod es.Add(objReqTy pe.Name)

Next objReqType
End If
Next objBaseline
Next objProject

Exit Sub

End Sub
"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
the code below dows not let me get the parent child view... all the nodes
are
show in one line only...

also i need them to be collasped ...

Thanks ..


Private Sub GetTree()
Dim objNode As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
objNode = New TreeNode
objNode.Text = TextBox1.Text
TreeView1.Nodes .Add(objNode)

For Each objProject In objSession.Proj ects

objNode = TreeView1.Nodes .Add(objProject .Name)

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

objNode = TreeView1.Nodes .Add(objBaselin e.Name)

If objBaseline.Nam e = "Default View" Then
objNode.Text = "Current Baseline"
Else
objNode.Text = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so user
can cancel

objNode = TreeView1.Nodes .Add(objReqType .Name)

Next objReqType
End If
Next objBaseline
Next objProject
objNode = Nothing
Exit Sub

End Sub

Nov 21 '05 #2
Thank you soo much that helped.

Iam trying to add image to each level.

i have it as:

root.imageindex = 0
firstlevel.imag eindex = 1 and so on..

i add this below the
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

initally it show all the images right.. but when i click any child or parent
it changes to image to the image of the root.

why wud that happen

thank you

"Robin Tucker" wrote:
Yes, you have effectively built a flat tree. At each nesting level, you
need to add the nodes further down the branches to their parent - so, simply
store the parent in "root", "firstlevel ", "secondleve l" etc.....
Try this....


Private Sub GetTree()
Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

For Each objProject In objSession.Proj ects

firstLevel = root.Nodes.Add( objProject.Name )

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

secondLevel= firstLevel.Node s.Add(objBaseli ne.Name)

If objBaseline.Nam e = "Default View" Then
secondLevel.Tex t = "Current Baseline"
Else
secondLevel.Tex t = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so user
can cancel

thirdLevel = secondLevel.Nod es.Add(objReqTy pe.Name)

Next objReqType
End If
Next objBaseline
Next objProject

Exit Sub

End Sub
"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
the code below dows not let me get the parent child view... all the nodes
are
show in one line only...

also i need them to be collasped ...

Thanks ..


Private Sub GetTree()
Dim objNode As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
objNode = New TreeNode
objNode.Text = TextBox1.Text
TreeView1.Nodes .Add(objNode)

For Each objProject In objSession.Proj ects

objNode = TreeView1.Nodes .Add(objProject .Name)

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

objNode = TreeView1.Nodes .Add(objBaselin e.Name)

If objBaseline.Nam e = "Default View" Then
objNode.Text = "Current Baseline"
Else
objNode.Text = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so user
can cancel

objNode = TreeView1.Nodes .Add(objReqType .Name)

Next objReqType
End If
Next objBaseline
Next objProject
objNode = Nothing
Exit Sub

End Sub


Nov 21 '05 #3
Well, there are two image indices - one is ImageIndex and the other I think
is SelectedIndex (or something) - you can effectively use one icon for when
it's selected and another for when it isn't. For now, set
selectedimagein dex to the same as you set imageindex and all will be well.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
Thank you soo much that helped.

Iam trying to add image to each level.

i have it as:

root.imageindex = 0
firstlevel.imag eindex = 1 and so on..

i add this below the
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

initally it show all the images right.. but when i click any child or
parent
it changes to image to the image of the root.

why wud that happen

thank you

"Robin Tucker" wrote:
Yes, you have effectively built a flat tree. At each nesting level, you
need to add the nodes further down the branches to their parent - so,
simply
store the parent in "root", "firstlevel ", "secondleve l" etc.....
Try this....


Private Sub GetTree()
Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

For Each objProject In objSession.Proj ects

firstLevel = root.Nodes.Add( objProject.Name )

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

secondLevel= firstLevel.Node s.Add(objBaseli ne.Name)

If objBaseline.Nam e = "Default View" Then
secondLevel.Tex t = "Current Baseline"
Else
secondLevel.Tex t = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so
user
can cancel

thirdLevel =
secondLevel.Nod es.Add(objReqTy pe.Name)

Next objReqType
End If
Next objBaseline
Next objProject

Exit Sub

End Sub
"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
> the code below dows not let me get the parent child view... all the
> nodes
> are
> show in one line only...
>
> also i need them to be collasped ...
>
> Thanks ..
>
>
>
>
> Private Sub GetTree()
> Dim objNode As TreeNode
> Dim i, j As Integer
>
> TreeView1.Image List = ImageList1
>
> 'Create the Server Node
> objNode = New TreeNode
> objNode.Text = TextBox1.Text
> TreeView1.Nodes .Add(objNode)
>
> For Each objProject In objSession.Proj ects
>
> objNode = TreeView1.Nodes .Add(objProject .Name)
>
> 'Loop thru Baselines
> For Each objBaseline In objProject.Base lines
> If objBaseline.Nam e <> "Deleted View" Then
>
> objNode = TreeView1.Nodes .Add(objBaselin e.Name)
>
> If objBaseline.Nam e = "Default View" Then
> objNode.Text = "Current Baseline"
> Else
> objNode.Text = objBaseline.Nam e
> End If
> For Each objReqType In objBaseline.Req uirementTypes
> Application.DoE vents() ' Allow for a break, so
> user
> can cancel
>
> objNode = TreeView1.Nodes .Add(objReqType .Name)
>
> Next objReqType
> End If
> Next objBaseline
> Next objProject
> objNode = Nothing
> Exit Sub
>
> End Sub


Nov 21 '05 #4
Thanks for ur help..

if i use Treeview.Afters elect does not let me go to the lowest level to
select a node... I want to travel to the last node or the deepest node at
thirdlevel and then check the type of the node selected and go from there...

if i use afterselect it immediately goes to the fucntion as soon as clik any
node in the tree..

thank you

"Robin Tucker" wrote:
Well, there are two image indices - one is ImageIndex and the other I think
is SelectedIndex (or something) - you can effectively use one icon for when
it's selected and another for when it isn't. For now, set
selectedimagein dex to the same as you set imageindex and all will be well.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
Thank you soo much that helped.

Iam trying to add image to each level.

i have it as:

root.imageindex = 0
firstlevel.imag eindex = 1 and so on..

i add this below the
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

initally it show all the images right.. but when i click any child or
parent
it changes to image to the image of the root.

why wud that happen

thank you

"Robin Tucker" wrote:
Yes, you have effectively built a flat tree. At each nesting level, you
need to add the nodes further down the branches to their parent - so,
simply
store the parent in "root", "firstlevel ", "secondleve l" etc.....
Try this....


Private Sub GetTree()
Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

'Create the Server Node
root= New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

For Each objProject In objSession.Proj ects

firstLevel = root.Nodes.Add( objProject.Name )

'Loop thru Baselines
For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

secondLevel= firstLevel.Node s.Add(objBaseli ne.Name)

If objBaseline.Nam e = "Default View" Then
secondLevel.Tex t = "Current Baseline"
Else
secondLevel.Tex t = objBaseline.Nam e
End If
For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() ' Allow for a break, so
user
can cancel

thirdLevel =
secondLevel.Nod es.Add(objReqTy pe.Name)

Next objReqType
End If
Next objBaseline
Next objProject

Exit Sub

End Sub
"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
> the code below dows not let me get the parent child view... all the
> nodes
> are
> show in one line only...
>
> also i need them to be collasped ...
>
> Thanks ..
>
>
>
>
> Private Sub GetTree()
> Dim objNode As TreeNode
> Dim i, j As Integer
>
> TreeView1.Image List = ImageList1
>
> 'Create the Server Node
> objNode = New TreeNode
> objNode.Text = TextBox1.Text
> TreeView1.Nodes .Add(objNode)
>
> For Each objProject In objSession.Proj ects
>
> objNode = TreeView1.Nodes .Add(objProject .Name)
>
> 'Loop thru Baselines
> For Each objBaseline In objProject.Base lines
> If objBaseline.Nam e <> "Deleted View" Then
>
> objNode = TreeView1.Nodes .Add(objBaselin e.Name)
>
> If objBaseline.Nam e = "Default View" Then
> objNode.Text = "Current Baseline"
> Else
> objNode.Text = objBaseline.Nam e
> End If
> For Each objReqType In objBaseline.Req uirementTypes
> Application.DoE vents() ' Allow for a break, so
> user
> can cancel
>
> objNode = TreeView1.Nodes .Add(objReqType .Name)
>
> Next objReqType
> End If
> Next objBaseline
> Next objProject
> objNode = Nothing
> Exit Sub
>
> End Sub


Nov 21 '05 #5
If you want to go to the lowest level to select a node, then you need some
algorithms :) ; recursive tree traversals to find the "leaves".

When you say "you want to travel", do you mean "you" the program, or "you"
the user. If the user selects a node, you don't have a problem. If you
want to programatically choose a node or group of nodes, you need to be more
specific. Please enlighten me as to which node or nodes you want to check
and why you want to check them. We can then figure an algorithm to do this.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:7F******** *************** ***********@mic rosoft.com...
Thanks for ur help..

if i use Treeview.Afters elect does not let me go to the lowest level to
select a node... I want to travel to the last node or the deepest node at
thirdlevel and then check the type of the node selected and go from
there...

if i use afterselect it immediately goes to the fucntion as soon as clik
any
node in the tree..

thank you

"Robin Tucker" wrote:
Well, there are two image indices - one is ImageIndex and the other I
think
is SelectedIndex (or something) - you can effectively use one icon for
when
it's selected and another for when it isn't. For now, set
selectedimagein dex to the same as you set imageindex and all will be
well.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
> Thank you soo much that helped.
>
> Iam trying to add image to each level.
>
> i have it as:
>
> root.imageindex = 0
> firstlevel.imag eindex = 1 and so on..
>
> i add this below the
> root= New TreeNode
> root.Text = TextBox1.Text
> TreeView1.Nodes .Add(root)
>
> initally it show all the images right.. but when i click any child or
> parent
> it changes to image to the image of the root.
>
> why wud that happen
>
> thank you
>
> "Robin Tucker" wrote:
>
>> Yes, you have effectively built a flat tree. At each nesting level,
>> you
>> need to add the nodes further down the branches to their parent - so,
>> simply
>> store the parent in "root", "firstlevel ", "secondleve l" etc.....
>>
>>
>> Try this....
>>
>>
>>
>>
>> Private Sub GetTree()
>> Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
>> Dim i, j As Integer
>>
>> TreeView1.Image List = ImageList1
>>
>> 'Create the Server Node
>> root= New TreeNode
>> root.Text = TextBox1.Text
>> TreeView1.Nodes .Add(root)
>>
>> For Each objProject In objSession.Proj ects
>>
>> firstLevel = root.Nodes.Add( objProject.Name )
>>
>> 'Loop thru Baselines
>> For Each objBaseline In objProject.Base lines
>> If objBaseline.Nam e <> "Deleted View" Then
>>
>> secondLevel=
>> firstLevel.Node s.Add(objBaseli ne.Name)
>>
>> If objBaseline.Nam e = "Default View" Then
>> secondLevel.Tex t = "Current Baseline"
>> Else
>> secondLevel.Tex t = objBaseline.Nam e
>> End If
>> For Each objReqType In objBaseline.Req uirementTypes
>> Application.DoE vents() ' Allow for a break, so
>> user
>> can cancel
>>
>> thirdLevel =
>> secondLevel.Nod es.Add(objReqTy pe.Name)
>>
>> Next objReqType
>> End If
>> Next objBaseline
>> Next objProject
>>
>> Exit Sub
>>
>> End Sub
>>
>>
>> "amruta" <am****@discuss ions.microsoft. com> wrote in message
>> news:2A******** *************** ***********@mic rosoft.com...
>> > the code below dows not let me get the parent child view... all the
>> > nodes
>> > are
>> > show in one line only...
>> >
>> > also i need them to be collasped ...
>> >
>> > Thanks ..
>> >
>> >
>> >
>> >
>> > Private Sub GetTree()
>> > Dim objNode As TreeNode
>> > Dim i, j As Integer
>> >
>> > TreeView1.Image List = ImageList1
>> >
>> > 'Create the Server Node
>> > objNode = New TreeNode
>> > objNode.Text = TextBox1.Text
>> > TreeView1.Nodes .Add(objNode)
>> >
>> > For Each objProject In objSession.Proj ects
>> >
>> > objNode = TreeView1.Nodes .Add(objProject .Name)
>> >
>> > 'Loop thru Baselines
>> > For Each objBaseline In objProject.Base lines
>> > If objBaseline.Nam e <> "Deleted View" Then
>> >
>> > objNode = TreeView1.Nodes .Add(objBaselin e.Name)
>> >
>> > If objBaseline.Nam e = "Default View" Then
>> > objNode.Text = "Current Baseline"
>> > Else
>> > objNode.Text = objBaseline.Nam e
>> > End If
>> > For Each objReqType In
>> > objBaseline.Req uirementTypes
>> > Application.DoE vents() ' Allow for a break,
>> > so
>> > user
>> > can cancel
>> >
>> > objNode =
>> > TreeView1.Nodes .Add(objReqType .Name)
>> >
>> > Next objReqType
>> > End If
>> > Next objBaseline
>> > Next objProject
>> > objNode = Nothing
>> > Exit Sub
>> >
>> > End Sub
>>
>>
>>


Nov 21 '05 #6
Hi,
Thank you for ur help.

The user needs to select the last child node in a tree. for ex:
child1---
Child2----
Child3.

so the user need to select child3 and then click a button to perform some
action.

Hope iam being clear.

Thank you.


"Robin Tucker" wrote:
If you want to go to the lowest level to select a node, then you need some
algorithms :) ; recursive tree traversals to find the "leaves".

When you say "you want to travel", do you mean "you" the program, or "you"
the user. If the user selects a node, you don't have a problem. If you
want to programatically choose a node or group of nodes, you need to be more
specific. Please enlighten me as to which node or nodes you want to check
and why you want to check them. We can then figure an algorithm to do this.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:7F******** *************** ***********@mic rosoft.com...
Thanks for ur help..

if i use Treeview.Afters elect does not let me go to the lowest level to
select a node... I want to travel to the last node or the deepest node at
thirdlevel and then check the type of the node selected and go from
there...

if i use afterselect it immediately goes to the fucntion as soon as clik
any
node in the tree..

thank you

"Robin Tucker" wrote:
Well, there are two image indices - one is ImageIndex and the other I
think
is SelectedIndex (or something) - you can effectively use one icon for
when
it's selected and another for when it isn't. For now, set
selectedimagein dex to the same as you set imageindex and all will be
well.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
> Thank you soo much that helped.
>
> Iam trying to add image to each level.
>
> i have it as:
>
> root.imageindex = 0
> firstlevel.imag eindex = 1 and so on..
>
> i add this below the
> root= New TreeNode
> root.Text = TextBox1.Text
> TreeView1.Nodes .Add(root)
>
> initally it show all the images right.. but when i click any child or
> parent
> it changes to image to the image of the root.
>
> why wud that happen
>
> thank you
>
> "Robin Tucker" wrote:
>
>> Yes, you have effectively built a flat tree. At each nesting level,
>> you
>> need to add the nodes further down the branches to their parent - so,
>> simply
>> store the parent in "root", "firstlevel ", "secondleve l" etc.....
>>
>>
>> Try this....
>>
>>
>>
>>
>> Private Sub GetTree()
>> Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
>> Dim i, j As Integer
>>
>> TreeView1.Image List = ImageList1
>>
>> 'Create the Server Node
>> root= New TreeNode
>> root.Text = TextBox1.Text
>> TreeView1.Nodes .Add(root)
>>
>> For Each objProject In objSession.Proj ects
>>
>> firstLevel = root.Nodes.Add( objProject.Name )
>>
>> 'Loop thru Baselines
>> For Each objBaseline In objProject.Base lines
>> If objBaseline.Nam e <> "Deleted View" Then
>>
>> secondLevel=
>> firstLevel.Node s.Add(objBaseli ne.Name)
>>
>> If objBaseline.Nam e = "Default View" Then
>> secondLevel.Tex t = "Current Baseline"
>> Else
>> secondLevel.Tex t = objBaseline.Nam e
>> End If
>> For Each objReqType In objBaseline.Req uirementTypes
>> Application.DoE vents() ' Allow for a break, so
>> user
>> can cancel
>>
>> thirdLevel =
>> secondLevel.Nod es.Add(objReqTy pe.Name)
>>
>> Next objReqType
>> End If
>> Next objBaseline
>> Next objProject
>>
>> Exit Sub
>>
>> End Sub
>>
>>
>> "amruta" <am****@discuss ions.microsoft. com> wrote in message
>> news:2A******** *************** ***********@mic rosoft.com...
>> > the code below dows not let me get the parent child view... all the
>> > nodes
>> > are
>> > show in one line only...
>> >
>> > also i need them to be collasped ...
>> >
>> > Thanks ..
>> >
>> >
>> >
>> >
>> > Private Sub GetTree()
>> > Dim objNode As TreeNode
>> > Dim i, j As Integer
>> >
>> > TreeView1.Image List = ImageList1
>> >
>> > 'Create the Server Node
>> > objNode = New TreeNode
>> > objNode.Text = TextBox1.Text
>> > TreeView1.Nodes .Add(objNode)
>> >
>> > For Each objProject In objSession.Proj ects
>> >
>> > objNode = TreeView1.Nodes .Add(objProject .Name)
>> >
>> > 'Loop thru Baselines
>> > For Each objBaseline In objProject.Base lines
>> > If objBaseline.Nam e <> "Deleted View" Then
>> >
>> > objNode = TreeView1.Nodes .Add(objBaselin e.Name)
>> >
>> > If objBaseline.Nam e = "Default View" Then
>> > objNode.Text = "Current Baseline"
>> > Else
>> > objNode.Text = objBaseline.Nam e
>> > End If
>> > For Each objReqType In
>> > objBaseline.Req uirementTypes
>> > Application.DoE vents() ' Allow for a break,
>> > so
>> > user
>> > can cancel
>> >
>> > objNode =
>> > TreeView1.Nodes .Add(objReqType .Name)
>> >
>> > Next objReqType
>> > End If
>> > Next objBaseline
>> > Next objProject
>> > objNode = Nothing
>> > Exit Sub
>> >
>> > End Sub
>>
>>
>>


Nov 21 '05 #7
Without getting too complicated (ie. I would derive new classes from
TreeViewItem so you can identify what "type" of object the tree node is,
regardless of it's "level"), you can find the depth of the item in the tree
by doing something like this:

Dim theDepth as integer =
TreeView.Select edNode.FullPath .Split("\"c).Le ngth()

If your tree structure is fixed with a depth of 4 (including the root), then
you will know what type of item the user is working with when he clicks the
button, or you can do this in "after select" to switch available buttons on
or off depending on which type of node the user has selected:

Select Case theDepth

case 1

' The root item

case 2

' an objProject

case 3

' an objBaseline

case 4

' an objReqType

End Select
If you then want to modify the properties of the item representing this in
the tree, well, things get a bit more complicated. What I do is ALWAYS
create a hashtable with a tree view to hash some key value to the actual
tree view item.

So,

Private m_Hash as New HashTable
and then when you build your tree........


Private Sub GetTree()

Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
Dim i, j As Integer

TreeView1.Image List = ImageList1

root = New TreeNode
root.Text = TextBox1.Text
TreeView1.Nodes .Add(root)

m_Hash.Add ( root.FullPath, root )

For Each objProject In objSession.Proj ects

firstLevel = root.Nodes.Add( objProject.Name )

For Each objBaseline In objProject.Base lines
If objBaseline.Nam e <> "Deleted View" Then

secondLevel= firstLevel.Node s.Add(objBaseli ne.Name)

If objBaseline.Nam e = "Default View" Then
secondLevel.Tex t = "Current Baseline"
Else
secondLevel.Tex t = objBaseline.Nam e
End If

m_Hash.Add ( secondLevel.Ful lPath, secondLevel )

For Each objReqType In objBaseline.Req uirementTypes
Application.DoE vents() '
thirdLevel = secondLevel.Nod es.Add(objReqTy pe.Name)
m_Hash.Add ( thirdLevel.Full Path, thirdLevel )

Next objReqType

End If

Next objBaseline
Next objProject

End Sub


now, using the above code, fetching the object represented by your tree view
item is simply a case of doing this:
Dim theObject as Object = m_Hash ( TreeView1.Selec tedNode.FullPat h )
' Cast the object to whatever, according to what type it is:
If TypeOf ( theObject ) Is objProjectClass Then

Dim theObjProject as objProjectClass = DirectCast(theO bject,
theObjProjectCl ass )

ElseIf TypeOf ( theObject ) Is objBaselineClas s Then

Dim theObjBaseline as objBaselineClas s = DirectCast(theO bject,
objBaselineClas s )

ElseIf TypeOf ( theObject ) Is objReqTypeClass Then

Dim theObjReqType as objReqTypeClass = DirectCast(theO bject,
objReqTypeClass )

End If



I would like to suggest you switch ON option STRICT and option Explicit.
You will find it catches a lot of annoying bugs ;)

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:86******** *************** ***********@mic rosoft.com...
Hi,
Thank you for ur help.

The user needs to select the last child node in a tree. for ex:
child1---
Child2----
Child3.

so the user need to select child3 and then click a button to perform some
action.

Hope iam being clear.

Thank you.


"Robin Tucker" wrote:
If you want to go to the lowest level to select a node, then you need
some
algorithms :) ; recursive tree traversals to find the "leaves".

When you say "you want to travel", do you mean "you" the program, or
"you"
the user. If the user selects a node, you don't have a problem. If you
want to programatically choose a node or group of nodes, you need to be
more
specific. Please enlighten me as to which node or nodes you want to
check
and why you want to check them. We can then figure an algorithm to do
this.

"amruta" <am****@discuss ions.microsoft. com> wrote in message
news:7F******** *************** ***********@mic rosoft.com...
> Thanks for ur help..
>
> if i use Treeview.Afters elect does not let me go to the lowest level to
> select a node... I want to travel to the last node or the deepest node
> at
> thirdlevel and then check the type of the node selected and go from
> there...
>
> if i use afterselect it immediately goes to the fucntion as soon as
> clik
> any
> node in the tree..
>
> thank you
>
> "Robin Tucker" wrote:
>
>> Well, there are two image indices - one is ImageIndex and the other I
>> think
>> is SelectedIndex (or something) - you can effectively use one icon for
>> when
>> it's selected and another for when it isn't. For now, set
>> selectedimagein dex to the same as you set imageindex and all will be
>> well.
>>
>> "amruta" <am****@discuss ions.microsoft. com> wrote in message
>> news:66******** *************** ***********@mic rosoft.com...
>> > Thank you soo much that helped.
>> >
>> > Iam trying to add image to each level.
>> >
>> > i have it as:
>> >
>> > root.imageindex = 0
>> > firstlevel.imag eindex = 1 and so on..
>> >
>> > i add this below the
>> > root= New TreeNode
>> > root.Text = TextBox1.Text
>> > TreeView1.Nodes .Add(root)
>> >
>> > initally it show all the images right.. but when i click any child
>> > or
>> > parent
>> > it changes to image to the image of the root.
>> >
>> > why wud that happen
>> >
>> > thank you
>> >
>> > "Robin Tucker" wrote:
>> >
>> >> Yes, you have effectively built a flat tree. At each nesting
>> >> level,
>> >> you
>> >> need to add the nodes further down the branches to their parent -
>> >> so,
>> >> simply
>> >> store the parent in "root", "firstlevel ", "secondleve l" etc.....
>> >>
>> >>
>> >> Try this....
>> >>
>> >>
>> >>
>> >>
>> >> Private Sub GetTree()
>> >> Dim root, firstLevel, SecondLevel, thirdLevel As TreeNode
>> >> Dim i, j As Integer
>> >>
>> >> TreeView1.Image List = ImageList1
>> >>
>> >> 'Create the Server Node
>> >> root= New TreeNode
>> >> root.Text = TextBox1.Text
>> >> TreeView1.Nodes .Add(root)
>> >>
>> >> For Each objProject In objSession.Proj ects
>> >>
>> >> firstLevel = root.Nodes.Add( objProject.Name )
>> >>
>> >> 'Loop thru Baselines
>> >> For Each objBaseline In objProject.Base lines
>> >> If objBaseline.Nam e <> "Deleted View" Then
>> >>
>> >> secondLevel=
>> >> firstLevel.Node s.Add(objBaseli ne.Name)
>> >>
>> >> If objBaseline.Nam e = "Default View" Then
>> >> secondLevel.Tex t = "Current Baseline"
>> >> Else
>> >> secondLevel.Tex t = objBaseline.Nam e
>> >> End If
>> >> For Each objReqType In
>> >> objBaseline.Req uirementTypes
>> >> Application.DoE vents() ' Allow for a break,
>> >> so
>> >> user
>> >> can cancel
>> >>
>> >> thirdLevel =
>> >> secondLevel.Nod es.Add(objReqTy pe.Name)
>> >>
>> >> Next objReqType
>> >> End If
>> >> Next objBaseline
>> >> Next objProject
>> >>
>> >> Exit Sub
>> >>
>> >> End Sub
>> >>
>> >>
>> >> "amruta" <am****@discuss ions.microsoft. com> wrote in message
>> >> news:2A******** *************** ***********@mic rosoft.com...
>> >> > the code below dows not let me get the parent child view... all
>> >> > the
>> >> > nodes
>> >> > are
>> >> > show in one line only...
>> >> >
>> >> > also i need them to be collasped ...
>> >> >
>> >> > Thanks ..
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > Private Sub GetTree()
>> >> > Dim objNode As TreeNode
>> >> > Dim i, j As Integer
>> >> >
>> >> > TreeView1.Image List = ImageList1
>> >> >
>> >> > 'Create the Server Node
>> >> > objNode = New TreeNode
>> >> > objNode.Text = TextBox1.Text
>> >> > TreeView1.Nodes .Add(objNode)
>> >> >
>> >> > For Each objProject In objSession.Proj ects
>> >> >
>> >> > objNode = TreeView1.Nodes .Add(objProject .Name)
>> >> >
>> >> > 'Loop thru Baselines
>> >> > For Each objBaseline In objProject.Base lines
>> >> > If objBaseline.Nam e <> "Deleted View" Then
>> >> >
>> >> > objNode =
>> >> > TreeView1.Nodes .Add(objBaselin e.Name)
>> >> >
>> >> > If objBaseline.Nam e = "Default View" Then
>> >> > objNode.Text = "Current Baseline"
>> >> > Else
>> >> > objNode.Text = objBaseline.Nam e
>> >> > End If
>> >> > For Each objReqType In
>> >> > objBaseline.Req uirementTypes
>> >> > Application.DoE vents() ' Allow for a
>> >> > break,
>> >> > so
>> >> > user
>> >> > can cancel
>> >> >
>> >> > objNode =
>> >> > TreeView1.Nodes .Add(objReqType .Name)
>> >> >
>> >> > Next objReqType
>> >> > End If
>> >> > Next objBaseline
>> >> > Next objProject
>> >> > objNode = Nothing
>> >> > Exit Sub
>> >> >
>> >> > End Sub
>> >>
>> >>
>> >>
>>
>>
>>


Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3074
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value of the second table, etc. Parent varchar 3 Name varchar 60 Code varchar 3 WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <- UNC
1
1953
by: clintonG | last post by:
How do I get a TreeNode.Parent property when using the 2.0 TreeView control? When the data source is an XML file there may be redundant names in the tree. For example, when a child node with the value of 'name' is selected I don't have a clue how to get the name of its parent which may be 'person' or 'school.' <%= Clinton Gallagher
0
2224
by: Karthick Kumar | last post by:
Hi, I need to create a simple parent/child hierarchical menu. I have alread used the Treeview control but my requirement is slightly different than the Treeview control. I already have the kind of menu I am talking about, written in Classic ASP, but I need to write the entire menu thing in Asp.Net using CSharp. I have a Sql table which has large number of menu items with problemId and parentId, through which I am trying to create and...
5
4005
by: B-Dog | last post by:
I want to be able to detect if a user has selected a parent or child node in a treeview and depending on which is clicked act accordingly based on the tag. I can get the values but don't know if they are child or parent values. Thanks
1
2057
by: bill | last post by:
When PopulateOnDemand is true, the treeview event handler for the TreeNodePopulate event gets the TreeNodeEventArgs as a parameter. The TreeNodeEventArgs contains the tree node to be populated, and child nodes can be added to it. Why is the Parent of the node contained in TreeNodeEventArgs always equal to nothing? I'm not talking about the root node, but about nodes which have been added
2
4169
by: Bob | last post by:
Hi, I would to have a tree view control with check boxes in which the parent and child nodes interacts, in the way that you normally see this occuring. Checking the parent node automatically checks all its children node. Conversely, if one of the child nodes is unchecked, the parent node unchecks. Is there a property of the treeview that will automatically do this for me or do I need to roll my own? Thanks, Bob
6
2512
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node ?? When adding a new node is there any way to get an handle or something else to be able add the childs to the correct parent ? Thanks!
0
980
by: Limno | last post by:
Hi, I have a treeview control with showcheckboxes = All in my C#.net web application. When i check on the child node its parent node should be checked automatically.similarlly when i uncheck a parent node all its childnodes should be unckecked. When i check on the parent node all its child nodes should be checked automatically. How can i do this?
4
3582
by: jmDesktop | last post by:
I have searched everywhere and tried several things. I have a treeview with and want to be able to only select a parent node. For example: root //don't want to drag this -parent1 //yes, drag this an only this because it is a parent --childOfParent1 //cannot drag this, only the parent --childOfParent1 //can only drag parent -parent2 //yes, parent, can select and drag --childOfParent2 //no, cannot drag
0
8703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8893
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4389
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.