You can use TreeView.get_nodes()
and TreeNode.get_nodes()
but these only give you the immediate nodes, not their full descendants.
So for RadTreeView with varying levels of nodes, we need to have a recursive function to drill down into the whole nodes hierarchy.
This answer is adapted from wizpert's answer and this Telerik blog: http://www.telerik.com/blogs/how-to-get-the-checked-items-from-a-treeview-with-checkboxes
function OnClientDropDownClosed(sender, eventArgs)
{
// first let's get hold of the treeview (sender is the combobox)
var tree = sender.get_items().getItem(0).findControl("RadTreeView1");
// pass the treeview nodes to another function to find the checked nodes
var items = getCheckedNodes(tree.get_nodes());
var text = 'None selected'; // default text
if (items.length > 0)
{
var texts = [];
for (var i = 0; i < items.length; i++)
{
// extract the text only of the checked nodes
texts.push(items[i].get_text());
}
text = texts.join(', '); // comma separated text
}
sender.set_text(text); // set the combobox text
}
function getCheckedNodes(nodes) {
var node, childCheckedNodes;
var checkedNodes = []; // array of the checked nodes
for (var i = 0; i < nodes.get_count(); i++) {
node = nodes.getNode(i);
if (node.get_checked()) {
checkedNodes.push(node); // add to array if checked
}
// to understand recursion, first you must understand recursion
if (node.get_nodes().get_count() > 0)
{
// recursive function call
childCheckedNodes = getCheckedNodes(node.get_nodes());
if (childCheckedNodes.length > 0)
{
// append array with results from recursive call
checkedNodes = checkedNodes.concat(childCheckedNodes);
}
}
}
return checkedNodes;
}