Drag and Drop between two grid views exactly as shown the documentation

1 Answer 150 Views
GridView
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Patgat asked on 24 Oct 2022, 11:30 PM

Hi,

I am trying to do Drag&Drop as show in the Telerik documentation (see https://docs.telerik.com/devtools/winforms/controls/gridview/rows/drag-and-drop).

I tried to implement it in three different ways:

1) after reading the doc, I downloaded the code and build it with VS2022. This code uses .Net Framework 4.6.1 and works exactly as expected.

2) Then, I tried to add it to my current project using .Net 6 and the current Telerik Library. I did it both in the form where it should be used and in a dedicated form with the exact code provided. In both cases, I have the 'strange' behavior that the drag works but as soon as the grabed row is movingout of its origin,  a "no entry" sign is shown both in some area of the initial grid view and everywhere in the destination one (see picture).

3 Then I tried to do it in a brand new .Net 6 project to dismiss a potential setup in my project. In this third one evrything compile and run nicely, BUT there is absolutely no drag and drop behavior.

I attached this last project, but it is really exactly the downloaded code.

So can someone explain what is wrong in this code or my way to use it ?

Many thanks

Patrick

 

Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 25 Oct 2022, 09:29 AM

In addition to my previous message, I did a final trial. I took the code provided on Github (https://github.com/telerik/winforms-sdk/tree/master/GridView/DragAndDropBetweenGrids), opened it in VS2022, checked that it was nicely working (as previously said) and then upgraded the Telerik UI for Winforms version. The ruslt was exactly like in my point 3 : it compiles and run but drag drop is not anymore visible nor working.

Best

Patrick

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Oct 2022, 08:42 AM

Hello, Patrick,     

I have reviewed the initially provided sample project. It seems that you hit a known issue for .NET 6 in R3 2022 (version 2022.3.913) and the message filter we use in Telerik Presentation Framework. A fix was already introduced in R3 2022 SP1 (version 2022.3.921). Feel free to upgrade in order to benefit from the fix:

https://docs.telerik.com/devtools/winforms/installation-and-upgrades/latest-internal-builds#installing-lib-from-nuget 

Now, the drag and drop behavior works as expected:

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

Regards,
Dess | Tech Support Engineer, Principal
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/.

Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 26 Oct 2022, 06:42 PM

Hi Dess,

thanks for your answer. Effectively, the sample project works fine now with .Net 6.

However, I still have an issue when trying to use it, the same way with the same code, in my project.

As previously, it does it even if I do not start any other code than the sample one within my project.

Please have a look at the attached video and screenshots. I have tried many things and really don't have a clue.

Many thanks

Patrick

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 27 Oct 2022, 09:06 AM

Hello, Patrick,     

Indeed, the provided video illustrates that the drag and drop operation is not executed as expected. However, it wouldn't be easy to conclude what causes this undesired behavior on your end since I am not familiar with the exact implementation available in the project. Could you please elaborate?

Could you please confirm that the custom DragAndDropRadGrid is use din your project and the PreviewDragStart event is fired when dragging a row? You can inspect the Designer.cs file of the form and have a look at the type of the grid control. If it is the default RadGridView type, not the custom DragAndDropRadGrid, the custom code is not used at all. 

In case you are still experiencing any further difficulties, I would kindly ask you to submit a private support ticket and provide the sample runnable project demonstrating the problem you are facing. Thus, we would be able to make an adequate analysis of the precise case and provide further assistance. Thank you in advance.

I hope this information helps. 
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 27 Oct 2022, 10:26 AM

Hi Dess,

thanks for your quick answer.

I confirm that the custom DragAndDropRadGrid is used in my project and the PreviewDragStart event is fired when dragging a row

This said, I looked,following your suggestion, to the events fired and noticed that in PreviewDragOver, the expected  type for DragInstance is a GridDataRowElement. However in my case (and I don't know why) the type is a SnapshotDragItem (see picture).  I tried changing the expected type to this last one and the dragging is working (until some exception occurs later).

Thanks for your feedback

Best

Patrick

Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 27 Oct 2022, 10:47 AM

Hi again,

following my previous message I did try the following modified code :

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

        var dropTarget = e.HitTarget as RadItem;
        var targetGrid = dropTarget.ElementTree.Control as RadGridView;
        if (targetGrid == null)
        {
            return;
        }
        GridDataRowElement rowElement = ((SnapshotDragItem)e.DragInstance).Item as GridDataRowElement;
        var dragGrid = rowElement.ElementTree.Control as RadGridView;
. . .

And it seems to work fine now.

But a confirmation would be welcomed

Best

Patrick

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 28 Oct 2022, 04:35 AM

Hi, Patrick,

If the DragInstance is SnapshotDragItem in the PreviewDragOver, make sure that tha CanDrop argument is set to true in this case in order to allow dropping on the target. Then, in the PreviewDragDrop event you can get the GridDataRowElement by the SnapshotDragItem.Item property as you have already found out.  

The following KB article is another example how to plug into the drag and drop operation that RadGridView offers and customize the behavior according to the custom requirements that a developer may have:

https://docs.telerik.com/devtools/winforms/knowledge-base/gridview-drag-cell-and-copy 

I believe that you will find it useful.

Tags
GridView
Asked by
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or