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

DragEnter & DragOver events not firing

6 Answers 1478 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Arash
Top achievements
Rank 1
Veteran
Arash asked on 19 Oct 2020, 09:41 AM

Hi,

There are a few articles/posts that seem to have answer and resolved this issue but in actual fact, I still cannot get this feature to work with Telerik RadGridView.

So I appreciate your help.

 

I've implemented a working version of this example: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/drag-and-drop

I now want to handle DragEnter & DragOver events for the target grids.

I've read all relevant articles but none seem to work. The events do not fire!

Could you provide a working source code for the article above where the two events do actually fire please?

The only way I could get this to work is by using Microsoft's Control.DoDragDrop method which is I know is not the correct way as it mixes Telerik's and Microsoft's approaches.

Thanks

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Oct 2020, 12:16 PM

Hello, Arash, 

By default, RadGridView supports rows drag and drop functionality in unbound mode out of the box. It is necessary to set the RadGridView.AllowRowReorder property to true and start reordering the rows.

When RadGridView is in bound mode, drag and drop functionality is not supported out of the box because of the specificity of the DataSource collection of the source and target grid. However, such a functionality can be easily achieved by the RadGridViewDragDropService. RadGridView handles the whole drag and drop operation by its RadGridViewDragDropService.

The PreviewDragOver event allows you to control on what targets the row being dragged can be dropped on. The PreviewDragDrop event allows you to get a handle on all the aspects of the drag and drop operation, the source (drag) grid, the destination (target) control, as well as the row being dragged. This is where we will initiate the actual physical move of the row(s) from one grid to the target control. 

I have prepared a sample project for your reference which result is illustrated in the below gif file. Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your custom requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Arash
Top achievements
Rank 1
Veteran
answered on 19 Oct 2020, 12:26 PM

Hi,

 

Thanks for your reply but that's not what I was asking for and you've given me the code which is already available here: https://github.com/telerik/winforms-sdk/tree/master/GridView/DragAndDropBetweenGrids

My questions is about "DragEnter & DragOver events not firing" not firing. I could be wrong but your reply does not address that issue.

I've come across other posts from you with code snippets trying to get these events to work/fire, but non of them work.

So, can I ask very clearly, is there an example showing clearly that the two events do fire/work for the grid to grid drag and drop?

Thanks

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Oct 2020, 12:38 PM

Hi, Arash,

As it was previously noted, by default, RadGridView handles the drag and drop operation by its RadGridViewDragDropService. The mentioned events, DragEnter and DragOver, are relevant for the OLE drag-and-drop functionality and they are not supposed to be fired if you use the RadGridViewDragDropService.

In case you don't want to use the available service in RadGridView, an alternative approach is to implement the desired drag and drop behavior with the standard approach supported by all MS standard WinForms control. A sample tutorial is demonstrated in the following MSDN article: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/walkthrough-performing-a-drag-and-drop-operation-in-windows-forms?view=netframeworkdesktop-4.8

The following forum post also demonstrates a sample approach of using the OLE drag drop and achieving dragging a file from Outlook and dropping onto the grid: https://www.telerik.com/forums/drag-and-drop-into-radgrid 

However, I believe that the RadGridViewDragDropService would also fit your scenario even though it provides other public events

Feel free to use this approach which suits your requirements best.

However, if you are still experiencing any further difficulties, it would be greatly appreciated if you can provide more details about the exact goal that you are trying to achieve. Thus, we would be able to get better understanding of the precise case and think about a suitable solution.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Arash
Top achievements
Rank 1
Veteran
answered on 19 Oct 2020, 01:12 PM

Hi Dess,

I do want to use RadGridView and RadGridViewDragDropService rather than MS standard controls but it just seems there are some functionality that are not achievable by the Telerik controls and drag drop service.

These include;

- highlighting the target row while hovering in drag drop mode

- getting the target row's cell values on drag enter/drop

 

Thanks

 

 

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Oct 2020, 05:14 AM

Hello, Arash, 

It is possible to highlight the target row and extract its cells' values while dragging over. Please refer to the following code snippet. I have also attached a sample project for your reference. Please give it a try and see how it works on your end.

    GridDataRowElement lastTargetRow = null;
    StringBuilder sb;
    private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
    {
        if (e.DragInstance is GridDataRowElement)
        {
            e.CanDrop = e.HitTarget is GridDataRowElement ||
                        e.HitTarget is GridTableElement ||
                        e.HitTarget is GridSummaryRowElement;
            GridDataRowElement targetRow = e.HitTarget as GridDataRowElement;
            if (lastTargetRow != null)
            { 
                lastTargetRow.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                lastTargetRow.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            }
            if (targetRow != null)
            {
                targetRow.DrawFill = true;
                targetRow.BackColor = Color.Yellow;
                sb = new StringBuilder();
                foreach (GridViewCellInfo cell in targetRow.RowInfo.Cells)
                {
                    sb.Append(cell.Value + "; ");
                }
                this.FindForm().Text = sb.ToString();
            }
            lastTargetRow = e.HitTarget as GridDataRowElement;
        }
    }

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Arash
Top achievements
Rank 1
Veteran
answered on 31 Oct 2020, 07:40 AM
That's great. Thanks Dess 
Tags
GridView
Asked by
Arash
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Arash
Top achievements
Rank 1
Veteran
Share this question
or