views:

290

answers:

1

I am using ComponentArt Third party controls for ASP.NET 2.0. Here is the problem i am facing.

I created some ComponentArt.Web.UI.TreeView at runtime on Page_Load. Now at click event of a button, i want to get values of the selected nodes in the treeview.

Can someone help ....!

+2  A: 

Firstly I'm assuming you have MultipleSelectEnabled set to true to allow the selection of multiple nodes in the TreeView.

If you have that you can use the MultipleSelectedNodes property of the TreeView to get an array of TreeViewNodes.

From here you just need to iterate through the array and use the Value property of the nodes to get what you need.

So essentially something like this should work,

TreeViewNodes[] selectedNodes = treeViewID.MultipleSelectedNodes;
ArrayList values = new ArrayList(selectedNodes.Count);
foreach (TreeViewNode node in selectedNodes) {  
    values.Add(node.Value);
}

And now you have your selected node values in the ArrayList.

Denis Sadowski
If by selected nodes you meant there will only be a single node selected at a time, then its even easier as the TreeView has a property called SelectedNode. So no loop iteration will be necessary.
Denis Sadowski