0

I am using Dev Components Advance TreeView controls in my C# Win Forms application. The tree view nodes have check boxes to select/deselect the node. I have enabled multiple selection of nodes in the tree view. I want to get all the selected nodes on "check/uncheck" of any node. I tried using treeview's "SelectedNodes" property that returns collection of Selected Nodes but some how it always returns "1" nod e.g. last selected Node.

Update The problem is with selection of Children Nodes. If I multi select all the parent nodes then I get the right count back but in case of Children Nodes the count is always 1 Kindly suggest

V.B
  • 1,191
  • 7
  • 29
  • 55

1 Answers1

0

You could use a simple recursive function, just pass the root node in here. If you don't want recursion, hook a selected node list into the event handler for check/uncheck.

     static public List<HierarchyNode> GetCheckedNodes(HierarchyNode node)
    {
        var nodes = new List<HierarchyNode>();

        foreach (HierarchyNode childNode in node.Nodes)
        {
            nodes.AddRange(GetCheckedNodes(childNode));
        }

        if (node.Checked)
        {
            nodes.Add(node);
        }

        return nodes;
    }
Mark Terry
  • 51
  • 1
  • 4