Drag and Drop to RadGridView with Multiple Templates

1 Answer 27 Views
General Discussions GridView
F3M
Top achievements
Rank 2
F3M asked on 07 Mar 2024, 06:37 PM

I have 2 grids with drag and drop capability, one of them is just a simple grid with 2 columns, the other grid is a grid with 3 Hierarchical Templates that have 3 associated BindingSources.

How can I, when dragging and dropping from the simple grid to the hierarchical grid, determine which Template I am dragging the row to and add it to that Template/BindingSources?

I used exactly the example code you have here (https://docs.telerik.com/devtools/winforms/controls/gridview/rows/drag-and-drop), and indeed everything works.

I just wanted to understand if it's possible to know which Template the row is being dragged to and add it exactly to that Template.

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 12 Mar 2024, 02:23 PM

Hello, 

Thank you for writing.

Here is how you can get the template you are dragging the row into the target hierarchy grid:

private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
{
    var rowElement = e.DragInstance as GridDataRowElement;
    if (rowElement == null)
    {
        return;
    }
    e.Handled = true;

    var dropTarget = e.HitTarget as GridDataRowElement;
    var targetGrid = dropTarget.ElementTree.Control as RadGridView;
    if (targetGrid == null)
    {
        return;
    }

    var dragGrid = rowElement.ElementTree.Control as RadGridView;

    if (targetGrid != dragGrid)
    {
        e.Handled = true;
        int hierarchylevel = dropTarget.RowInfo.HierarchyLevel;
        GridViewTemplate template = dropTarget.GridControl.CurrentRow.ViewTemplate;
       // TO DO
}
}

I hope this helps. Let me know if you have other questions.

Regards,
Nadya | 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
General Discussions GridView
Asked by
F3M
Top achievements
Rank 2
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or