Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
Questionhow to copy cheked nodes from a treeview to to new treeview? Pin
JANARDHAN GURRAM2-Jan-12 7:08
JANARDHAN GURRAM2-Jan-12 7:08 
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 
Well, we are making progress in defining the actual structure of your TreeView ... and that's good Smile | :)

This reply raises these questions, for me:

0. is any node in the TreeView ever more than 3 levels deep: in other words: is the level of "nesting" arbitrary ? In other words: is there any regular structure to all nodes that we can assume: for example: they are all 3 levels "deep" ?

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 ?

a. what if the grandparent node of the only child of the parent node that is unchecked has many other child nodes ... "uncle nodes" ? Smile | :) ... what happens to them: do they get left alone, or unchecked, also ?

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: this would be "symmetric" with the way you now handle unchecking an only child of a node, then its parent, and then its grandparent.

2. is it ever the case that:

a. new nodes are added at run-time ?

b. existing nodes are deleted at run-time ?

To get you started with recursive parsing: put a TreeView on a Form:

0. in the Form Load EventHandler set the 'Expanded property of the TreeView to 'true.

1. edit the Nodes collection at Design-Time, and add a whole bunch of them, nested to various depths

2. set the TreeView 'CheckBoxes property to 'True:

3. put a button on the Form with its Click EventHandler set like so:
C#
private void button1_Click(object sender, EventArgs e)
{
   // show all the nodes expanded
   treeView1.ExpandAll();

   RecursiveParseTree(treeView1.Nodes, 0);
}
4. And then define the recursive parser:
private void RecursiveParseTree(TreeNodeCollection nodeCollection, int level)
{
    foreach (TreeNode theNode in nodeCollection)
    {
        Console.WriteLine
        (
            "Node Name: = {0}, 
            Node Level = {1}, 
            Node Checked = {2}", 
            theNode.Text, 
            level, 
            theNode.Checked
        );

        if (theNode.Nodes.Count > 0)
        {
            RecursiveParseTree(theNode.Nodes, level++);
        }
    }
}
5. At run-time check a bunch of nodes at various "depths," and examine the output of running this code in VS's Output Window when you exit the Application.

Discussion: the interesting part is going to be where you get to all the business related to unchecking only-child nodes, and grandparent nodes !

best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle


modified 3-Jan-12 5:25am.

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 
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 

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.