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

Drag tree node text to RichTextBox

3 Answers 133 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Richard Slade
Top achievements
Rank 2
Richard Slade asked on 04 Sep 2009, 11:26 AM
Hello,

I'd like to be able to drag a tree node to a RichTextBox and have the text appear on the RichTextBox. I don't want to be able to drag nodes into other nodes, or other controls.

I have tried getting some of the code from your demos, but I end up with text in the textbox, even when it's not dragged over it.

Any help appreciated.
thanks

3 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 04 Sep 2009, 10:04 PM
Hi Richard,

I think the following will accomplish what you are trying to do.

namespace TreeNodeDrag 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
         
            richTextBox1.AllowDrop = true
        } 
 
        private void radTreeView1_MouseDown(object sender, MouseEventArgs e) 
        { 
            radTreeView1.DoDragDrop(radTreeView1.SelectedNode.Text, DragDropEffects.Move); 
        } 
    } 

- Robert
0
Richard Slade
Top achievements
Rank 2
answered on 07 Sep 2009, 08:09 AM
Thanks for the reply. I ended up with pretty much the same just before you had replied. I've also raised a support ticket though as I have to set the current Selected Node to Nothing. If I don't do that, then the expand and collapse no longer works via the + - symbols..
Have you had the same issue?
Cheers
Richard
0
Victor
Telerik team
answered on 07 Sep 2009, 10:11 AM
Hi Richard Slade,

Here is how this can be done. This approach is the same as I suggested in the support ticket you posted about a similar issue:
Public Class Form1 
    Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
        AddHandler Me.RadTreeView1.MouseDown, AddressOf HandleMouseDown 
        AddHandler Me.RichTextBox1.DragEnter, AddressOf RtbDragEnter 
        AddHandler Me.RichTextBox1.DragDrop, AddressOf RtbDragDrop 
        Me.RichTextBox1.AllowDrop = True 
    End Sub 
 
    Private Sub HandleMouseDown(ByVal sender As ObjectByVal args As MouseEventArgs) 
        Dim node As RadTreeNode = Me.RadTreeView1.GetNodeAt(args.X, args.Y) 
        If Not node Is Nothing Then 
            Me.RadTreeView1.DoDragDrop(node.Text, DragDropEffects.Move) 
        End If 
    End Sub 
 
    Private Sub RtbDragEnter(ByVal sender As ObjectByVal args As DragEventArgs) 
        If (args.Data.GetDataPresent(GetType(String))) Then 
            args.Effect = DragDropEffects.Move 
        Else 
            args.Effect = DragDropEffects.None 
        End If 
    End Sub 
 
    Private Sub RtbDragDrop(ByVal sender As ObjectByVal args As DragEventArgs) 
        Me.RichTextBox1.Text = DirectCast(args.Data.GetData(GetType(String)), String
    End Sub 
End Class 

Write again if you need further assistance.

Best wishes,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Treeview
Asked by
Richard Slade
Top achievements
Rank 2
Answers by
Robert
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Victor
Telerik team
Share this question
or