This is a migrated thread and some comments may be shown as answers.

Programmatically selected nodes can't get_nodes()

1 Answer 45 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 31 Jan 2013, 08:00 PM
We are using 2 treeviews to allow users to move items from one to the other.  After moving the selected items, we are programmatically setting the next node available as selected. When we try to multi-select again after the move we get the following error:

Microsoft JScript runtime error: Unable to get value of the property 'get_nodes': object is null or undefined

Here is a snippet of our JS source.
function Left() {
    if (availableTree.get_selectedNode()) {
        var sourceNodes = availableTree.get_selectedNodes();
        var index = sourceNodes[0].get_index();
        var destNodeList = selectedTree.get_nodes();
        var destNode;
        if (destNodeList) {
            destNode = destNodeList.getNode(0);
            }
        onNodeDroppingPrivate(availableTree, sourceNodes, destNode, "add");
        if (availableTree.get_nodes().get_count() == index) {
            index = index - 1;
        }
        availableTree.get_nodes().getNode(index).set_selected(true);
    }
    else {
        alert("Please select a service level to transfer");
    }
    SetSaveToFalse();
 
}
 
function onNodeDroppingPrivate(sender, sourceNodes, destinationNode, position) {
    var retVal = dropOnTree(sourceNodes); /*gets value of dragged node*/
    if (retVal != "0") {
        clientSideEdit(sender, sourceNodes, destinationNode, position);
    }
    else {
        alert("There are no service levels to transfer.");
    }
    SetSaveToFalse();
}
 
function dropOnTree(sourceNodes) {
    var text = "";
 
    if (sourceNodes.length) {
        var i;
        for (i = 0; i < sourceNodes.length; i++) {
 
            var node = sourceNodes[i];
            if (node.get_attributes().getAttribute("Category") == "true") {
                node = node.get_nodes().getNode(0);
            }
            text = node.get_value();
            break;
        }
    }
    return text;
}
 
function clientSideEdit(sender, sourceNodes, destinationNode, position) {
    availableTree.trackChanges();
    selectedTree.trackChanges();
 
    if (destinationNode)
    {
        for (var i = 0; i < sourceNodes.length; i++) {
            var sourceNode = sourceNodes[i];
            var sourceParent = sourceNode.get_parent();
            sourceParent.get_nodes().remove(sourceNode);
 
            if (sourceParent.get_nodes().get_count() == 0) {
                var node = new Telerik.Web.UI.RadTreeNode();
                node.set_value("0");
                if (sourceParent.get_id() == availableTree.get_id())
                    {
                    node.set_text("All available service levels have been selected.");
                    }
                    else
                    {
                    node.set_text("No service levels have been selected.");
                    }
                sourceParent.get_nodes().add(node);
            }
            if (position == "over") insertAfter(destinationNode, sourceNode);
            if (position == "above") insertBefore(destinationNode, sourceNode);
            if (position == "below") insertAfter(destinationNode, sourceNode);
            if (position == "add") add(destinationNode, sourceNode);
        }
 
        destinationNode.set_expanded(true);
 
        availableTree.commitChanges();
        selectedTree.commitChanges();
    }
}
function add(destinationNode, sourceNode) {
    var destinationParent = destinationNode.get_parent();
    GetAttribute(destinationParent, sourceNode);
    /* If destination parent contains 'No Nodes exist', new node added takes its place*/
    if (destinationParent.get_nodes().getNode(0).get_value() == "0") {
        destinationParent.get_nodes().getNode(0).set_text(sourceNode.get_text());
        destinationParent.get_nodes().getNode(0).set_value(sourceNode.get_value());
        AddTheEditButton(destinationParent.get_nodes().getNode(0), destinationParent.get_nodes().getNode(0));
    }
    else {
        if (destinationParent.get_id() == selectedTree.get_id()) {
            addEditButton(destinationNode, sourceNode, "add", 0);
        }
        else {
            destinationParent.get_nodes().add(sourceNode);
            sourceNode.set_checked(true);
        }
    }
 
    return "false";
}

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 05 Feb 2013, 11:12 AM
Hello Seth,

Please take a look at this demo of the RadTreeView control where you can find a working example of the functionality that you are trying to achieve. In the demo, you can easily select multiple nodes the first time the drag and drop them (repeating these steps does not invoke any exception). Give it a try and in case it does not help I would suggest that you open a support ticket where you can attache you simplified runnable project so we can inspect it locally and help you out.

Regards,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Seth
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or