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

DragDropManager with TextBox

4 Answers 120 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 07 Aug 2013, 09:07 AM
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?


4 Answers, 1 is accepted

Sort by
0
Charles Willwerth
Top achievements
Rank 1
answered on 12 Aug 2013, 05:23 AM
I'm also interested in the answer to this question.
0
Dimitrina
Telerik team
answered on 14 Aug 2013, 03:22 PM
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 >>
0
Jason
Top achievements
Rank 1
answered on 15 Aug 2013, 05:48 AM
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


 




0
Dimitrina
Telerik team
answered on 15 Aug 2013, 07:57 AM
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 >>
Tags
DragAndDrop
Asked by
Jason
Top achievements
Rank 1
Answers by
Charles Willwerth
Top achievements
Rank 1
Dimitrina
Telerik team
Jason
Top achievements
Rank 1
Share this question
or