c# - How to get TreeView behaviour for TreeNodes that when you check one, it checks all its children TreeNodes? -


This is how most of the applications behave I thought that TreeView worked by default in this way.

Is there any way to do this, or do I have to check all the children in the treeoid and have to check them out?

This is Vanforma.

You have to do it yourself, which is not very difficult on the other side:

Private Zero TreeView_AfterCheck (Object Sender, TreeViewEventArgs E) {SetChildrenChecked (e.Node, e.Node.Checked); } Private Zero SetChildrenChecked (TreeNode treeNode, bool checkedState) {foreName (TreeNode item in treeNode.Nodes) {item.Checked = checkedState; }}

It takes care of checking and unchecking all children (no matter how many levels can have hair nodes below).

Update
Expanded code sample which will check / uncheck the parent node if all its child nodes are checked or manually unchecked (fully If it has not been tested, it can probably be done more beautifully):

  Private Zero TreeView_AfterCheck {Object Sender, TreeViewEventArgs E} {SetChildrenChecked (e.Node, e.Node.Checked ); If (e.Node.Parent! = Null) {bool setParentChecked = true; Foreach (Tree node node in e.Node.Parent.Nodes) {if (node ​​check! = E.Node.Checked) {setParentChecked = false; break; }} If (setcertcracked) {e.Node.Parent.Checked = e.Node.Checked; }}} Private Zero Set Child Check (Tree node Paid node, Balls checked stat) {foreach (Tree node item in tree nodes.) {If (item check! = Checkstate) {item.Checked = checkedState; }}}  

If

has been added to the child-checked system , then in that case StackOverflowException < / Code>, where you check the nodes with the child nodes, they check, and when the last time the parents (which you click on) are checked, it is stopped and < Code> AfterCheck event runs again (which makes me wonder a bit; when checked does not change the value of the property, then the event It should be raised, but it is already assigned to the same value, but then the event is called AfterCheck , not converted after inquiry ).


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -