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

Dragging a node, selects the node

1 Answer 16 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jamie ooms
Top achievements
Rank 1
jamie ooms asked on 17 Jun 2010, 03:52 PM
Hello,

Im trying the trail of Telerik currently. I'm very pleased with ur product and we will most likely buy a developer licence soon.
I have a question.

When dragging a node is it possible to not select the node.

eg:

I have a treeview with lots of nodes. A user can select a node and then the details screen is shown on the right.
When a node is selected the user can drag another node to a grid on the right screen.

The problem i have is that the node that was left clicked should stay selected.
But when u start to drag another node, this dragged node gets the selected style.

Is it possible to leave the selected style to the node that was left clicked?

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 23 Jun 2010, 12:29 PM
Hi Jamie,

Sorry for the late response!
I've tried to compensate this by providing you with full example just for your requirements.

It holds one constraint (my solution), though:
- You have to use the NodeClicked event to remember the last clicked node (in the solution I am trapping it client-side, by you can use the server-side if needed);

Anyway, I think that you already have implemented it as required and even if you didn't it will be fairly easy to migrate (just to handle different event with the same handler).

Here is the complete example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     
    <asp:ScriptManager runat="server">
    </asp:ScriptManager>
 
    <script type="text/javascript">
        var lastSelectedNode;
 
        function onNodeClicked(sender,args)
        {
            lastSelectedNode=args.get_node();
            var label=$telerik.$("#label");
            label.text(lastSelectedNode.get_text() + "clicked!");
        }
 
        function onNodeDragging(sender,args)
        {
            if(lastSelectedNode)
            {
                lastSelectedNode.set_selected(true);
            }
        }
 
        function onNodeDropped(sender,args)
        {
            var tree=sender;
             
            var destinationNodeDomElement = args._domEvent.target;
             
            var destinationNode=tree._extractNodeFromDomElement(destinationNodeDomElement);
            var destinationNodeNodes=destinationNode.get_nodes();
 
            var droppedNodes = args.get_sourceNodes();
            var droppedNodesCount = droppedNodes.length;
 
            for(var i=0;i<droppedNodesCount;i++)
            {
                destinationNodeNodes.add(droppedNodes[i]);
            }
        }
    </script>
 
    <telerik:RadTreeView runat="server" ID="treeView" EnableDragAndDrop="true" OnClientNodeClicked="onNodeClicked" OnClientNodeDragging="onNodeDragging" OnClientNodeDropped="onNodeDropped">
        <Nodes>
            <telerik:RadTreeNode AllowDrag="false" Text="Root">
                <Nodes>
                    <telerik:RadTreeNode Text="Child 1" />
                    <telerik:RadTreeNode Text="Child 2" />
                    <telerik:RadTreeNode Text="Child 3" />
                    <telerik:RadTreeNode Text="Child 4" />
                    <telerik:RadTreeNode Text="Child 5" />
                    <telerik:RadTreeNode Text="Child 6" />
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>
 
    <span>
        <asp:Label runat="server" ID="label" />
    </span>
 
    </div>
    </form>
</body>
</html>

Hope this is going to help you!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
jamie ooms
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or