[Solved] Drag and Drop to RadGridView with Multiple Templates

2 Answers 229 Views
General Discussions GridView
F3M
Top achievements
Rank 2
Iron
Iron
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.

2 Answers, 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.

0
F3M
Top achievements
Rank 2
Iron
Iron
answered on 13 Apr 2026, 03:12 PM

Hi Nadya,

Sorry for the late response — I’ve only just picked the project back up for testing, and I’m now encountering an error.

I’m not sure if I might be doing something incorrectly, but here’s what I’m seeing:

Could you please take a look or let me know if I might be missing something?

Thanks in advance.

Best regards


Nadya | Tech Support Engineer
Telerik team
commented on 15 Apr 2026, 11:06 AM

Hello,

If ElementTree return nothing, it means that dropTarget is not GridDataRowElement. Can you specify where exactly you drop the row on your side, is it above GridDataRowElement or not?

To protect from some errors, you can check if ElementTree returns null, then proceed with getting the RadGridView instance.

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

// TO DO

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

 

Tags
General Discussions GridView
Asked by
F3M
Top achievements
Rank 2
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
F3M
Top achievements
Rank 2
Iron
Iron
Share this question
or