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

GridView to Diagram - Drag & Drop

2 Answers 121 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Joel Palmer
Top achievements
Rank 2
Joel Palmer asked on 05 May 2015, 01:32 AM

Do you have an example that would show me how to drag and drop between a RadGridView and a RadDiagram?

 

Thanks for your help,

Joel

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 05 May 2015, 09:21 AM
Hello Joel,

No we do not have such example but drag/drop between RadDiagram and another control could be quite straight forward. You can use the DragDropManager to achieve your requirement. Basically, you can subscribe for its DragInitialize event and in the event handler create new DiagramDropInfo with the shape that will be generated from the grid row's data. Here is an example:
DragDropManager.AddDragInitializeHandler(this.gridView, OnGridViewDragInit);
//.........
private void OnGridViewDragInit(object sender, DragInitializeEventArgs e)
{
    var gridViewRow = e.OriginalSource as GridViewRow;
    if (gridViewRow != null)
    {
        e.AllowedEffects = DragDropEffects.Copy;
        MyRowDataObject data = (MyRowDataObject)gridViewRow.DataContext;
 
        var shape = new RadDiagramShape() { Content = data }; // or whatever shape or configuration you need for the diagram
         
        var dropInfo = new DiagramDropInfo(new Size(100, 100), SerializationService.Default.SerializeItems(new List<IDiagramItem> { shape }));
 
        e.Data = dropInfo;
        e.DragVisual = new TextBlock() { Text = data };
    }
}
I also attached a sample project demonstrating this approach. Please give it a try and let me know if it helps.

Regards,
Martin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Joel Palmer
Top achievements
Rank 2
answered on 06 May 2015, 06:13 PM
This looks great.  I'll give it a try.
Tags
Diagram
Asked by
Joel Palmer
Top achievements
Rank 2
Answers by
Martin Ivanov
Telerik team
Joel Palmer
Top achievements
Rank 2
Share this question
or