This is a migrated thread and some comments may be shown as answers.
drag and drop behavior
3 Answers 16 Views
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Veteran
Claude asked on 10 Jan 2021, 01:02 AM

I am using your drag and drop service between grids.  Code is working fine for 10 rows.  Lager multirow selections error out.  I have experimented and have determined that if the rows are not showing in the grid I get this error.  For example, if my grid visually shows 10 rows and I select all of those rows and drag them to another grid all works fine.

If I select the first row and scroll down to select the 11th row while holding down the shift key, all eleven rows are selected.  However dragging then to the other grid I get an error in the svc_PreviewDragDrop method on the line:      var dragGrid = rowElement.ElementTree.Control as RadGridView;

 

Error Message below:

Date Time:1/9/2021 6:45:16 PM
Exception Name:Object reference not set to an instance of an object.
Event Name:System.NullReferenceException: Object reference not set to an instance of an object.
   at SmartView_V2.frmMainForm.svc_PreviewDragDrop(Object sender, RadDropEventArgs e) in C:\Users\claud\Documents\Visual Studio 2019\Projects\SmartView V2\frmMainForm.cs:line 2387
Control Name:svc_PreviewDragDrop
Form Name:frmMainForm

 

 

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Jan 2021, 10:44 AM

Hello, Claude,   

Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. This explains that when you scroll to select row 11, row 1 gets outside the view and its visual element is not associated with the respective data row any more because you don't need a visual element for it anymore. 

According to the provided information, it is not clear what is the exact custom implementation that you have on your end. However, I believe that you follow a similar approach as the one demonstrated here: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/drag-and-drop 
In the PreviewDragStart event you can store the data rows (GridViewDataRowInfo objects) from the SelectedRows collection. Then, in the PreviewDragDrop event you can use this stored collection with data rows and execute the drop action you need. Thus, you are not expected to experience any problems since you wouldn't be working with the visual row elements that are being reused after scrolling. A similar approach is used in this article: https://docs.telerik.com/devtools/winforms/controls/gridview/drag-and-drop/rows-reordering-in-master-detail-hierarchy 

Please give this solution a try on your end and see how it works for your scenario. However, if you are still experiencing any further difficulties, it would be greatly appreciated if you can provide a sample project demonstrating the undesired behavior that you are facing. Thus, we would be able to investigate the precise case and provide further assistance.

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

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
Claude
Top achievements
Rank 1
Veteran
answered on 13 Jan 2021, 11:18 PM

OK, It seems to be working better, but sometimes the currentrow does not get transferred.  It stays in the original grid, but I am using this code provided fore this.

if (dragGrid.CurrentRow != null)
                {
                    GridViewRowInfo row = dragGrid.CurrentRow;
                    if (!rows.Contains(row))
                        rows.Add(row);
                }

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Jan 2021, 10:21 AM
Hello, Claude,   

Usually, the CurrentRow is also selected. Hence, it is expected to be present in the SelectedRows collection. However, if in some cases it isn't, your code seems to be OK for ensuring that the CurrentRow will be also dragged. 

Should you have further questions please let me know.

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/.

Asked by
Claude
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Claude
Top achievements
Rank 1
Veteran
Share this question
or