Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > radtreeview drag

Not answered radtreeview drag

Feed from this thread
  • Posted on Nov 12, 2011 (permalink)

    Hi,

    I'm trying to drag a radtreeview node into a radtextbox. I just want the information stored in the node "ToolTipText" to be displayed in the radtextbox.I did the following:
    1. Set radtreeview AllowDragDrop to true
    2. Set readtxtbox AllowDrop to true
    3. In order to block radtreeview nodes to be moved in the tree I implemented a "DragEnding" event:
    private void treeview_DragEnding(object sender, Telerik.WinControls.UI.RadTreeViewDragCancelEventArgs e)
    {
    e.Cancel = true;
    }

     

    4. I also implemented a "ItemDrag":

    private void treeview_ItemDrag(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
    {
        DoDragDrop(e.Node, DragDropEffects.Copy);
    }

    5. In the radtextbox I implementeded the following "DragEnter" event:

    private void textbox_DragEnter(object sender, DragEventArgs e)
    {
        IDataObject dataObject = e.Data;
        if (dataObject == null)
            e.Effect = DragDropEffects.None;
        else
        {
            Telerik.WinControls.UI.RadTreeNode Node = dataObject.GetData(typeof(Telerik.WinControls.UI.RadTreeNode)) as Telerik.WinControls.UI.RadTreeNode;
            if (Node != null)
                e.Effect = e.AllowedEffect;
            else
                e.Effect = DragDropEffects.None;
        }
    }

    6. I also implemented the "DragDrop"event for the textbox:

    private void textbox_DragDrop(object sender, DragEventArgs e)
    {
        IDataObject dataObject = e.Data;
        if (dataObject != null)
        {
                Telerik.WinControls.UI.RadTreeNode Node = dataObject.GetData(typeof(Telerik.WinControls.UI.RadTreeNode)) as Telerik.WinControls.UI.RadTreeNode;
                if (Node != null)
                    textbox.Text = textbox.Text.Insert(textbox.SelectionStart, "Ok");
        }
    }

    the problem is that the opration is not working. When I move a node over the radtextbox the program frozes. I used the VS "debug | break all" menu option and the stack has a lot of "_ItemDrag" event calls.

    Any ideas?

    Thanks,

    Francisco


    Reply

  • Stefan Stefan admin's avatar

    Posted on Nov 16, 2011 (permalink)

    Hi Francisco,

    Thank you for writing.

    Attached you can find a sample project demonstrating the desired functionality. I am using the NodeMouseDown event in order to start the drag and drop operation and this way dragging into RadTreeView is disabled. 

    Let me know how this works for you.
     
    All the best,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

    Attached files

    Reply

  • Posted on Nov 16, 2011 (permalink)

    Stefan

    Your solution solves the drag and drop, but it also stops the "onclick" event from firing, and it doesn't solve the other problem I was seeing with the "ItemDrag" event being fired repeatedly. I used a different solution that covers both these problems:

    First, I changed the "ItemDrag" event to avoid the repeated firing. For this, I use an internal variable that has the node the user dragged; if it's the same, the event does nothing.  
    private void tvEntities_ItemDrag(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
    {
        // Start the drag and drop with the selected node
        if (LastDraggedNode != e.Node)
        {
            LastDraggedNode = e.Node;
            DoDragDrop(e.Node, DragDropEffects.Copy);
        }
    }

    Then, I changed the "DragDrop" event to report that the event was finished and to reset the "LastDraggedNode" variable as follows:
    private void rtbFilter_DragDrop(object sender, DragEventArgs e)
    {
        IDataObject dataObject = e.Data;
        if (dataObject != null)
        {
            // Handle the dropped info
            Telerik.WinControls.UI.RadTreeNode Node = dataObject.GetData(typeof(Telerik.WinControls.UI.RadTreeNode)) as Telerik.WinControls.UI.RadTreeNode;
            if (Node != null)
                textbox.Text = textbox.Text.Insert(textbox.SelectionStart, "Ok");

            // Report drop completed
            MessageHelper.SendWindowsMessage((int)this.Handle, MessageHelper.WM_DROPCOMPLETED, 0, 0);
        }
    }
     
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == MessageHelper.WM_DROPCOMPLETED)
            LastDraggedNode = null;
     
        base.WndProc(ref m);
    }

    The "MessageHelper" class is just a helper class that I built to send windows messages and do some other stuff. Thanks again for your help,

    Francisco

    Reply

  • Stefan Stefan admin's avatar

    Posted on Nov 21, 2011 (permalink)

    Hi Francisco,

    I am glad that I could help. If you have any other questions, do not hesitate to contact us.
     
    All the best,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > radtreeview drag