Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to copy cheked nodes from a treeview to to new treeview? Pin
Pete O'Hanlon2-Jan-12 10:34
mvePete O'Hanlon2-Jan-12 10:34 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
JANARDHAN GURRAM2-Jan-12 21:23
JANARDHAN GURRAM2-Jan-12 21:23 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
Pete O'Hanlon2-Jan-12 21:36
mvePete O'Hanlon2-Jan-12 21:36 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
JANARDHAN GURRAM2-Jan-12 21:59
JANARDHAN GURRAM2-Jan-12 21:59 
AnswerRe: how to copy cheked nodes from a treeview to to new treeview? Pin
BillWoodruff2-Jan-12 14:10
professionalBillWoodruff2-Jan-12 14:10 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
JANARDHAN GURRAM2-Jan-12 21:40
JANARDHAN GURRAM2-Jan-12 21:40 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
BillWoodruff2-Jan-12 23:04
professionalBillWoodruff2-Jan-12 23:04 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
JANARDHAN GURRAM2-Jan-12 23:49
JANARDHAN GURRAM2-Jan-12 23:49 
Smile | :)
i will answer your questions and i will give the code i wrote for checking subchilds so that it will be more clear for you.

0.Actually nodes in my treeview or folders and its subfolders are childs and sub subfolders are grand childs.when a user gives the folder by folderbrowser dialog i am capturing its path and extracting all its folder hierarchy and showing it in the treeview. so tree can be of any depth.

1.in the case of one node, which is the only child of its parent: you say the parent should also be unchecked: what about if that parent node is also the "only child" of its parent node: does its "grandfather" then get unchecked ?
-yes
a. what if the grandparent node of the only child of the parent node that is unchecked has many other child nodes ... "uncle nodes" ? ... what happens to them: do they get left alone, or unchecked, also ?
- uncle nodes state remains the same, only its parent node (if it is only child for it) is unchecked if it is unchecked.if it is checked obviously its parent node should be checked wether it has other childs or not.

2.if a parent node is unchecked: and that parent node has many levels of nested nodes "under it:" do they all get unchecked ... or only the "grandchildren" of that node get unchecked
-all the nodes shoould be unchecked


2.a. new nodes are added at run-time ? not added but checked or unchecked

b. existing nodes are deleted at run-time ?no not deleted but checked or unchecked.

hope this code will clarify your doubts :
    private void Load_treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
       {    // For Select all to sub tree
           TreeNode parent_node = e.Node;
           bool is_checked = parent_node.Checked;

           for (int i = 0; i <= e.Node.Nodes.Count - 1; i++)
           {
               //MessageBox.Show(i.ToString());
               SetSubtreeChecked(parent_node.Nodes[i], is_checked);

           }

           bool blnUncheck = false;

           //---------------------------------------------------
           //Check to see if a parent node exists.



           if ((e.Node.Parent != null))
           {
               //Loop through the child nodes.
               foreach (TreeNode child in e.Node.Parent.Nodes)
               {
                   //Check to see if the current node is unchecked.
                   if (child.Checked == true)
                   {
                      //Set the variable.
                       blnUncheck = true;
                   }
               }
               //Check the variable.
               if (blnUncheck == false)
               {
                   //Check the parent node.
                   e.Node.Parent.Checked = false;
               }
               else
               {
                   //Uncheck the parent node.
                   e.Node.Parent.Checked = true;
               }
           }
     }

private void SetSubtreeChecked(TreeNode parent_node, bool is_checked)
       {
           // Set the parent's Checked value.
           parent_node.Checked = is_checked;
           // Set the child nodes' Checked values.
           for (int i = 0; i <= parent_node.Nodes.Count - 1; i++)
           {
               SetSubtreeChecked(parent_node.Nodes[i], is_checked);
           }
       }

the recursive parsing code u gave looks solves the problem i will try that.Thank you Smile | :)
JANARDHAN

GeneralRe: how to copy cheked nodes from a treeview to to new treeview?<SOLVED> Pin
JANARDHAN GURRAM3-Jan-12 1:06
JANARDHAN GURRAM3-Jan-12 1:06 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
BillWoodruff3-Jan-12 2:51
professionalBillWoodruff3-Jan-12 2:51 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
JANARDHAN GURRAM5-Jan-12 18:17
JANARDHAN GURRAM5-Jan-12 18:17 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview? Pin
BillWoodruff5-Jan-12 22:38
professionalBillWoodruff5-Jan-12 22:38 
GeneralRe: how to copy cheked nodes from a treeview to to new treeview?<SOLVED> Pin
JANARDHAN GURRAM3-Jan-12 1:14
JANARDHAN GURRAM3-Jan-12 1:14 
QuestionProblem with Snake game in C# Pin
ori26942-Jan-12 3:20
ori26942-Jan-12 3:20 
AnswerRe: Problem with Snake game in C# Pin
Luc Pattyn2-Jan-12 3:42
sitebuilderLuc Pattyn2-Jan-12 3:42 
GeneralRe: Problem with Snake game in C# Pin
ori26942-Jan-12 4:31
ori26942-Jan-12 4:31 
Questionhow to preserve zero bebore number in csv file that opens on excell ? Pin
goldsoft2-Jan-12 0:23
goldsoft2-Jan-12 0:23 
AnswerRe: how to preserve zero bebore number in csv file that opens on excell ? Pin
Shameel2-Jan-12 2:18
professionalShameel2-Jan-12 2:18 
AnswerRe: how to preserve zero bebore number in csv file that opens on excell ? Pin
Richard MacCutchan2-Jan-12 3:35
mveRichard MacCutchan2-Jan-12 3:35 
GeneralRe: how to preserve zero bebore number in csv file that opens on excell ? Pin
Shameel2-Jan-12 3:44
professionalShameel2-Jan-12 3:44 
GeneralRe: how to preserve zero bebore number in csv file that opens on excell ? Pin
Richard MacCutchan2-Jan-12 3:57
mveRichard MacCutchan2-Jan-12 3:57 
QuestionHow to Convert Microsoft Office Word document to Image file such as Tiff? Pin
moslemB1-Jan-12 23:44
moslemB1-Jan-12 23:44 
QuestionRe: How to Convert Microsoft Office Word document to Image file such as Tiff? Pin
DaveAuld1-Jan-12 23:57
professionalDaveAuld1-Jan-12 23:57 
Questionmove from cells in dataGridview Pin
Nabawoka1-Jan-12 10:50
Nabawoka1-Jan-12 10:50 
AnswerRe: move from cells in dataGridview Pin
DaveAuld2-Jan-12 0:03
professionalDaveAuld2-Jan-12 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.