Drag Drop between winforms and WPF

1 Answer 87 Views
GridView
Fabrice
Top achievements
Rank 2
Iron
Iron
Fabrice asked on 27 Dec 2023, 08:10 AM

Hi,

 I’m trying to handle the drag and drop operation from a winforms control (RadGridView for now, can be RadTreeView or RadListView too) to the RadScheduleView WPF.

 I have overridden the ConvertDraggedData from ScheduleViewDragDropBehavior class.

 The event isn’t firing when I’m dragging a row from my winforms GridView over the schedule.

 Is there a way to convert dragged data from the grid in winforms that make the event fires in WPF?

 Or another way to achieve the expected behavior ?

 

 Thanks.

 Rémi

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 28 Dec 2023, 11:25 AM

Hi Fabrice,

Thank you for contacting us. I will start with the if your WF RadGridView is in bound mode, you will need to use MS Ole Drag Drop behavior to move the row and trigger the default drag-drop mechanism.

WinForms

public Form1()
{
    InitializeComponent();
    BindingList<Item> items = new BindingList<Item>();
    for (int i = 0; i < 5; i++)
    {
        items.Add(new Item(i, "Item" + i));
    }
    this.radGridView1.DataSource = items;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
          
    this.radGridView1.AllowDrop = true;
    this.radGridView1.MouseDown += RadGridView_MouseDown;

}

private void RadGridView_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left && this.radGridView1.CurrentRow != null)
        this.radGridView1.DoDragDrop(this.radGridView1.CurrentRow.Cells["Name"].Value, DragDropEffects.Copy | DragDropEffects.Move);
}

This way when you move the row across the WPF RadScheduleView, the ConvertDraggedData method will be triggered.

WPF

public class CustomDragDrop: ScheduleViewDragDropBehavior
{
    public override IEnumerable<IOccurrence> ConvertDraggedData(object data)
    {
        var dataObject = data as DataObject;
        var formats = dataObject.GetFormats();
        foreach (var item in formats)
        {
            var result2 = DragDropPayloadManager.GetDataFromObject(data,item );
        }

        return base.ConvertDraggedData(data);
    }
}

I have prepared a sample project which demonstrates the above code snippet. You could extend the code to transfer more data as a string so that you can get all the WF RadGridView dragged row cells in the WPF RadScheduleView control.

I hope that you can use this approach as a starting point to implement all your requirements.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Fabrice
Top achievements
Rank 2
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or