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

DragDrop between two RadGridView controls

3 Answers 230 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 19 Oct 2012, 09:01 AM
Hi, can ayone plese pont me to a current example of implementing DragDrop funcionality between two RadGridView controls?  I've looked through a lot of examples but they all look out of date?  What is the current/latest recomended implementation for DragDrop funcionality?

Many thanks,
Goran

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosen Vladimirov
Telerik team
answered on 19 Oct 2012, 10:27 AM
Hello Goran,

We are sorry for the caused confusion. We'll try to update our online help in the next days, but until then I'll try to explain you which of our controls you may use and the best approach to use them.

The RadDragAndDropManager is obsolete and we recommend you to use DragDropManager instead. The DragDropManager has several events (very similar to Microsoft's DragDrop scenarios) that can be used through the operation. They are explained in our online help here.

When using DragDropManager you can follow the steps below to implement a simple scenario in which you just want to drag from a source to a target and you want to set your own custom DragVisualElement to show while dragging the data.

1) Identify the element that will be a drag source. A drag source can be a UIElement or a ContentElement. Set the following property to true:

<Setter Property="telerik:DragDropManager.AllowDrag" Value="True"/>

2) Add a DragInitialize event handler to the source object. In this event you should set the data that will be dragged and dropped, and also your DragVisual

DragDropManager.AddDragInitializeHandler(source, OnDragInitialize);
  
private void OnDragInitialize(object sender, DragInitializeEventArgs args)
{
     args.Handled = true; 
}

4) If you want you can add a GiveFeedback handler to set the mouse cursor. This event is raised continuously while dragging:

DragDropManager.AddGiveFeedbackHandler(source, OnGiveFeedback);
  
private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args)
{
     if(args.Effects != DragDropEffects.None)
     {
          args.SetCursor(Cursors.Hand);
          args.Handled = true;
     }
}

5) Identify the element that will be a drop target. A drop target can be UIElement or a ContentElement.
6) On the drop target set the AllowDrop property to true.
7) Attach the drop handler to the target element. Here you can extract the data from the DragEventArgs that you have set in the DragInitialize event and also implement the change in the UI (for example add an item to a ListBox, etc.).

DragDropManager.AddDropHandler(target, OnDrop);
 
private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
{
      args.Handled = true;
}

8) Add a DragDropCompleted handler to the source. This event is raised after the drag and drop operation has succeeded. You can use it to change something in the source object (for example to remove the item from a ListBox that has been dropped in another one):

DragDropManager.AddDragDropCompletedHandler(source, OnDragCompleted);
  
public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args)
{
     args.Handled = true;
}

9) If you want you may also set add DragEnter, DragOver, DragLeave, etc. events to implement your logic.

To show you how to do this I'm sending an example for DragDrop between ListBox and RadGridView (attachment DragDropManager_SL_UsingEvents.zip).

For your scenario there is a simpler way to implement your logic. The DragDropManager is presenting the Behavior concept - by adding only three rows in your XAML you'll be able to implement full DragDropLogic for the specific controls. The RadGridView is one of the controls that has predefined behavior so you can just add the following lines to your code:

<telerik:GridViewDragDrop.Behavior>
    <telerik:GridViewDragDropBehavior AllowReorder="True" />
</telerik:GridViewDragDrop.Behavior>

More information for the behaviors and the possible use of a DataConverter can be found in our online help here. You may also check the online examples here as some of them are using behaviors.
For your convenience of the advantages of the behaviors I'm sending you another project (attachment DragDrop_btw_RadGridView.zip) where the DragDrop is implemented between two RadGridView  controls - you can check how simple and easy to use is this application.

Hopefully this clears the confusion. Don't hesitate to contact us if you still have any problems or concerns.

Regards,

Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Greg
Top achievements
Rank 2
answered on 22 Oct 2014, 03:19 PM
The UsingEvents project only has the project file - unusable...
0
Kalin
Telerik team
answered on 27 Oct 2014, 08:46 AM
Hi Greg,

We apologize for the inconvenience - please find attached the full project.

Hope this helps.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DragAndDrop
Asked by
Goran
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Greg
Top achievements
Rank 2
Kalin
Telerik team
Share this question
or