DragDropManager with TextBox

5 posts, 0 answers
  1. Jason
    Jason avatar
    9 posts
    Member since:
    Jul 2008

    Posted 07 Aug 2013 Link to this post

    There used to be support for dragging to/from RadControl to a TextBox (i.e.http://www.telerik.com/community/forums/silverlight/drag-and-drop/drag-and-drop-to-canvas.aspx and http://www.telerik.com/help/silverlight/raddraganddrop-from-textbox-to-another-control.html
    ). That doesn't seem to be supported anymore with DragDropManager? Am I mistaken?


  2. Charles Willwerth
    Charles Willwerth avatar
    3 posts
    Member since:
    Mar 2010

    Posted 12 Aug 2013 Link to this post

    I'm also interested in the answer to this question.
  3. DevCraft banner
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Aug 2013 Link to this post

    Hi,

    You can check this forum post on how to drop on a UserControl, there is also a demo project attached. You can also check our online documentation here.

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Jason
    Jason avatar
    9 posts
    Member since:
    Jul 2008

    Posted 15 Aug 2013 Link to this post

    Thank you for responding, but that doesn't apply to SILVERLIGHT.

    I had previously tried to work that example in Silverlight with no success. Of course, in Silverlight the method MainWindow.OnDragInitialize has to be changed. First, DataObject has no "SetText" method and only "SetData". Further, I receive a security error upon any call to dataobject.SetData. It is my understanding that I need to use "var payload = Telerik.Windows.DragDrop.DragDropPayloadManager.GeneratePayload(null);" and then use payload.SetData(...). 

    HOWEVER, after much trial and error, I finally figured out how to drag from a RadTreeView [or most other types of control] to a TextBox. The key piece was the Telerik.Windows.DragDrop.DragDropManager.AddDragOverHandler(...)....which didn't exist in the WPF example you referenced.

    Essentially, you need to do something like this (sorry I couldn't get format painter to work for me and if Telerik wants to edit my post to fix the formatting that is fine by me):

    First, set the TextBox to AllowDrop to True.

    ...next, the code....

    Telerik.Windows.DragDrop.DragDropManager.AddDragInitializeHandler(_radtree, _radtree_OnDragInitialize, true);

    Telerik.Windows.DragDrop.DragDropManager.AddDropHandler(_txtPropEditableTemplate, TextBox_OnDrop);

     Telerik.Windows.DragDrop.DragDropManager.AddDragOverHandler(_txtPropEditableTemplate, TextBox_OnDragOver);

    private void _radtree_OnDragInitialize(object sender, Telerik.Windows.DragDrop.DragInitializeEventArgs args)
    {
     args.AllowedEffects = DragDropEffects.All;

     var payload = Telerik.Windows.DragDrop.DragDropPayloadManager.GeneratePayload(null); 

     payload.SetData(typeof(string), "Text Comming From my treeview");

     args.Data = payload;

    }

     

    private void TextBox_OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)

    {

     e.Effects = DragDropEffects.Copy;

     e.Handled = true;  // *** Super important, if not specified to true, won't fire drop ***

    }

    private void TextBox_OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
    {
    //Catch drop here
    }



    It is noteworthy to point out that I couldn't get the following events to fire when they were hooked up to the textbox (perhaps I use these for the source control -- radtreeview)?

    Telerik.Windows.DragDrop.DragDropManager.AddGiveFeedbackHandler

    Telerik.Windows.DragDrop.DragDropManager.AddDragDropCompletedHandler


     




  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Aug 2013 Link to this post

    Hi,

    Generally, all you need is to add a handler for PreviewDropHandler for the TextBox control and get the payload. Please, refer to the attached project and let me know if this suits your needs.

    Let me know how this works for you.

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner