473,847 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to use a Treeview with checkboxes to get child nodes to be marked checked when parent node is checked.

Hello,

I am trying use a TreeView with checkboxes. I would like to check more than
one node and allow all child nodes of selected nodes to be checked or
unchecked with the parent is checked.

Thanks in advance for any help,

Jack
Nov 21 '05 #1
2 22080
Put this code for the AfterCheck Event for the Tree in your application. It
will recursively call itself until all levels under the tree node that was
checked are also checked.

Private Sub myTree_AfterChe ck(ByVal sender As Object, ByVal e As _
System.Windows. Forms.TreeViewE ventArgs) Handles MyTree.AfterChe ck
Dim t As TreeNode
For Each t In e.Node.Nodes
t.Checked = e.Node.Checked
Next
End Sub
--
Dennis in Houston
"Jack" wrote:
Hello,

I am trying use a TreeView with checkboxes. I would like to check more than
one node and allow all child nodes of selected nodes to be checked or
unchecked with the parent is checked.

Thanks in advance for any help,

Jack

Nov 21 '05 #2
Here is another approach:
The following code will allow you to
1. check / uncheck all the children nodes when you check/uncheck parent
node.
2. auto check the parent node if all of its child nodes are checked.
3. auto uncheck the parent node if one of its child node is uncheck.
'\\\
Private Sub CheckChildNode( ByVal currNode As TreeNode)
'set the children check status to the same as the current node
Dim checkStatus As Boolean = currNode.Checke d
For Each node As TreeNode In currNode.Nodes
node.Checked = checkStatus
CheckChildNode( node)
Next
End Sub

Private Sub CheckParentNode (ByVal currNode As TreeNode)
Dim parentNode As TreeNode = currNode.Parent
If parentNode Is Nothing Then Exit Sub
parentNode.Chec ked = True
For Each node As TreeNode In parentNode.Node s
If Not node.Checked Then
parentNode.Chec ked = False
Exit For
End If
Next
CheckParentNode (parentNode)
End Sub

Private Sub treeview_AfterC heck(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.TreeViewE ventArgs) Handles treeview.AfterC heck
RemoveHandler treeview.AfterC heck, AddressOf treeview_AfterC heck
CheckChildNode( e.Node)
CheckParentNode (e.Node)
AddHandler treeview.AfterC heck, AddressOf treeview_AfterC heck
End Sub
'///

HTH,

Kai


"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:04******** *************** ***********@mic rosoft.com...
Put this code for the AfterCheck Event for the Tree in your application.
It
will recursively call itself until all levels under the tree node that was
checked are also checked.

Private Sub myTree_AfterChe ck(ByVal sender As Object, ByVal e As _
System.Windows. Forms.TreeViewE ventArgs) Handles MyTree.AfterChe ck
Dim t As TreeNode
For Each t In e.Node.Nodes
t.Checked = e.Node.Checked
Next
End Sub
--
Dennis in Houston
"Jack" wrote:
Hello,

I am trying use a TreeView with checkboxes. I would like to check more
than
one node and allow all child nodes of selected nodes to be checked or
unchecked with the parent is checked.

Thanks in advance for any help,

Jack

Nov 21 '05 #3

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

Similar topics

1
1965
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
4
7602
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
7
3688
by: Ryan | last post by:
OK, here's my setup. I have a treeview control that is populated with records from a Product table, and it allows "checking". This is used for my automatic notification system. Say a particular Product is sold, any users who have that boxed checked will get a notification. So my (shortened) database layout is as such: Product Table ProductID (PK) ProductName
1
3283
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file exists just to sort of synchronize them by changing the xml nodes attribute(s). somehow i always catch an exception "blabla has an invalid token" but i cannot find a solution for this. maybe someone of you people can tell me how to do this...
1
2605
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file exists just to sort of synchronize them by changing the xml nodes attribute(s). somehow i always catch an exception "blabla has an invalid token" but i cannot find a solution for this. maybe someone of you people can tell me how to do this...
6
11976
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select is under NodeA or NodeB. I can do this by splitting the selectednode.fullpath of the child node but there must be a better way. Can any kind soul can enlighten me?
0
3317
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. Provide following view properties to listview, through View menu a. Tile b. Icon
2
3251
by: =?Utf-8?B?bWFib25k?= | last post by:
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.
1
6889
by: =?Utf-8?B?amV6MTIzNDU2?= | last post by:
Hi Experts I have a windows form with a TreeView control with the CheckBoxes property set to True. When I check a node, I want that node and all it's child nodes to be checked and expanded. I've tried various things but none seem to work correctly. Any ideas? thanks
0
9887
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
10648
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
10707
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
10341
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...
0
9485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7883
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
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.