Friday, December 25, 2015

How to expand selected node in treeview C#

When you try to expand selected node in treeview control dynamically, just use the following code:

           // get selected node
            TreeNode parentNode = tvItems.SelectedNode;

           // get top parent node
            while(parentNode.Parent != null)
            {
                parentNode = parentNode.Parent;
            }

           // find node by value path, then expand it
            tvItems.FindNode(parentNode.ValuePath).ExpandAll();



No comments:

Post a Comment