Drag tree node text to RichTextBox

4 posts, 0 answers
  1. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 04 Sep 2009 Link to this post

    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
  2. Robert
    Robert avatar
    82 posts
    Member since:
    Jun 2009

    Posted 04 Sep 2009 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Sep 2009 Link to this post

    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
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 07 Sep 2009 Link to this post

    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.
Back to Top