Drag-And-Drop from RadTextBox to another [external] control

2 posts, 0 answers
  1. Charles Willwerth
    Charles Willwerth avatar
    3 posts
    Member since:
    Mar 2010

    Posted 01 May 2012 Link to this post

    I want to drag element(s) from the RadTextBox to another control. Can you provide me an example as I have been unsuccessful making this work?

    To be clear, I understand how to do the reverse--as shown here. But that is not what I want. I want to drag information from the RadTextBox, as a copy and not a move, and then place that data into another control. I am pretty flexible if there are some limitations so dragging an image or text is fine. I have tried working with RadDragAndDropManager.AddDragInfoHandler and RadDragAndDropManager.AddDragQueryHandler with no success.

    Much thanks!

  2. Martin Ivanov
    Martin Ivanov avatar
    104 posts

    Posted 07 May 2012 Link to this post

    Hello Charles,

    We had not encountered your scenario till now. Unfortunately, you cannot use RadDragAndDropManager to drop items from the RadRichTextBox to other controls although the reverse scenario works fine. The reason for this is that mouse events are handled by the RRTB and don't reach the manager. However, you can try to implement your own logic for drag and drop. First of all you need to cancel the MoveSelectionCommand so that the selection would not be moved (as in cut), but copied. 

    void radRichTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
               if (e.Command is MoveSelectionCommand)
                   e.Cancel = true;

    Then you can attach to a mouse event of the desired control and having successfully found the proper place to insert text, get the selected text or DocumentFragment (basically a list of all selected document elements, paragraphs, images, etc.) obtained by one of the following two public methods:


    The first one will get you text, images, etc. while the second will contain only text. If you want to insert images and other rich text, you should use the CopySelectedDocumentElements method and traverse through the document fragment, filtering the custom information you need to insert into the other control. If you encounter difficulties, contact us back.

    All the best, Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
Back to Top