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

radtreeview drag

5 Answers 304 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
FRANCISCO C P RODRIGUES asked on 12 Nov 2011, 06:48 PM
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


5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Nov 2011, 10:41 AM
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.

0
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
answered on 16 Nov 2011, 02:27 PM
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
0
Stefan
Telerik team
answered on 21 Nov 2011, 10:41 AM
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.

0
Pascal
Top achievements
Rank 1
answered on 27 Nov 2012, 06:51 AM
Hi Franscico,
I would like to ask about the exact same scenario, with the drag and drop of a RadTreeNode, but this time i would like to visualize the data in a RadListview,
any help please.
0
Stefan
Telerik team
answered on 30 Nov 2012, 08:52 AM
Hello Pascal,

Thank you for writing.

I would suggest that you open a new forum/support thread with your inquiry, in order to avoid mixing different scenarios in the same thread. This way, it will be easier for the community to find the information needed. See p4 from this thread: http://www.telerik.com/community/forums/winforms/treeview/important-information-on-using-the-telerik-forums.aspx.

Also, when opening the new thread please provide information about the mode your RadListView is.  

Thank you for the understanding.

Greetings,
Stefan
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
Treeview
Asked by
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
Answers by
Stefan
Telerik team
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
Pascal
Top achievements
Rank 1
Share this question
or