c# - How to checked or unchecked all parent and child nodes separately by button click -


i have tree view has parent nodes , child nodes.i have 4 buttons. in 2 buttons of checked , unchecked parent nodes , 2 buttons of child nodes. want checked parent nodes if click btnallparentchecked , unchecked if click btnallparentunchecked , child nodes.i have done code child nodes.

boolean bchildtrigger = true;         boolean bparenttrigger = true;         private void checkallchildren(treenodecollection trnodecollection, boolean bcheck)         {             bparenttrigger = false;             foreach (treenode ctn in trnodecollection)             {                 bchildtrigger = false;                 ctn.checked = bcheck;                 bchildtrigger = true;                  checkallchildren(ctn.nodes, bcheck);             }             bparenttrigger = true;         }   private void btnallpropertychecked_click(object sender, eventargs e)         {             checkallchildren(treselector.nodes, true);         }  private void btnallpropertyunchecked_click(object sender, eventargs e)         {             checkallchildren(treselector.nodes, false);         } 

how can implement functionality in treeview?

this need. tested , works well

private void changenodesselection(treenodecollection node,bool docheck)     {         foreach (treenode n in node)         {             n.checked = docheck;             if (n.nodes.count > 0)             {                 changenodesselection(n.nodes,docheck);             }         }     }  private void uncheckparentnodes(treenodecollection node)     {         foreach (treenode n in node)         {             if (n.parent == null && n.nodes.count == 0)                 n.checked = false;         }     } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -