.NET TreeView causes application to crash when trying to check Parent node

Posted by alexD on Stack Overflow See other posts from Stack Overflow or by alexD
Published on 2010-05-21T20:06:11Z Indexed on 2010/05/21 20:10 UTC
Read the original article Hit count: 242

Filed under:
|
|
|
|

I have a TreeView with check boxes, and when a user checks a child node, I want to go up the tree and check each parent. However, for some reason my application blows up whenever I touch the parent node. For the nodes in my tree, I've extended TreeNode to create my own objects with some data that I need to store in them, but I still reference them as TreeNodes when checking/unchecking. My code looks like this:

//checkBox checked event handler
    if (node.Parent != null)
    {
        checkAllParents(node.Parent);
    }
//

private void checkAllParents(TreeNode node)
{
    node.Checked = true;
    if (node.Parent != null)
    {
       checkAllParents(node.Parent);
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about treeview