Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Treeview check change

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mabond - 29 Feb 2008 20:55 GMT
I'm using a treeview control.
One parent node, several child nodes, several grandchild nodes.
Each of the nodes has a checkbox.

My question, when the user changes the check value of one of the grandchild
nodes to true how do I automatically change that node's parent to check-true
and so on up the tree.....and in reverse if the parent is changed to
check-false how do I cascade that down to each of the child nodes and their
child nodes.

Any help appreciated

Michael Bond
Jack Jackson - 01 Mar 2008 06:25 GMT
>I'm using a treeview control.
>One parent node, several child nodes, several grandchild nodes.
[quoted text clipped - 9 lines]
>
>Michael Bond
Jack Jackson - 01 Mar 2008 06:36 GMT
Untested code.  To modify the parents, use the Parent property.

Dim parent as TreeNode = node.Parent

Do While parent IsNot Nothing Then
 parent.Checked = False
 parent = parent.Parent
Loop

To go the other way, you need to recurse through all of the children:

CheckChildren(node)

Private Sub CheckChildren(node As TreeNode)
Dim child as TreeNode = node.FirstNode

Do While child IsNot Nothing Then
 child.Checked = True
 CheckChildren(child)
 child = child.NextNode
Loop

End Sub

While that does what you asked, I'm not sure it is what you really
want.  If you check a node, all of the children get set.  But if you
uncheck one of those children, only the child's parents, grandparents,
etc. will be unchecked, not the child's siblings.

>I'm using a treeview control.
>One parent node, several child nodes, several grandchild nodes.
[quoted text clipped - 9 lines]
>
>Michael Bond

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.