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

Drag drop from grid methods called when dragging scrollbar

14 Answers 366 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Valerie
Top achievements
Rank 1
Valerie asked on 15 Nov 2012, 03:59 AM
When I drag the scrollbar in a RadGridView, OnDragInitialize is called. I can't find anything in the DragInitializeEvenArgs that could tell me whether the user is dragging the rows (in which case I am interested) or dragging the scrollbar (in which I want to ignore it). Ditto for the sender (the RadGridView). Its IsScrolling property is set to false whether I am scrolling or not.

How can I just do dragging when the user has chosen rows, and not other controls such as the scrollbar or vertical frozen column separator.

14 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 15 Nov 2012, 12:03 PM
Hello Valerie,

I suspect you have set AllowDrag to true on the GridView itself rather then on the rows. That is the reason you are getting drag initialize when scrolling. The best way to deal with this is to set AllowDrag for the GridViewRow like shown in our examples. An alternative is to use the OriginalSource property of the DragInitializeEventArgs to determine what is the exact source of the Drag operation.

Hope this helps! 

All the best,
Nikolay Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Valerie
Top achievements
Rank 1
answered on 15 Nov 2012, 12:44 PM
I solved half this problem. I realize that when restyling I had changed the target from the GridViewRow to the RadGridView. When I change it back to GridViewRow the scrollbar no longer participates in the drag. So this is solved.

The issue I still have is that the vertical column separator used to separate the frozen (ie, non scrollable) columns from the rest is calling the dragdrop behavior when trying to move it. That is, the mouse changes to a a double-pointed arrow when you hover over this vertical line, indicating that it can be moved. However once you click down and start to drag it, it switches to doing the row drag thing. I would be happy if the user wasn't allowed to drag this column in the middle of the grid (just allow it to be dragged from the column headers) but am not sure if that is a property I can change.
thanks
0
Nick
Telerik team
answered on 15 Nov 2012, 03:05 PM
Hello Valerie,

Unfortunately I am not able to reproduce the issue on our end. Can you provide some more details on your Rows Drag and Drop implementation?

Looking forward to hearing from you! 

Regards,
Nikolay Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Valerie
Top achievements
Rank 1
answered on 15 Nov 2012, 04:19 PM
Thank you Nikolay. I too discovered that independently (I posted early this morning).
I still have the problem with the vertical frozen column separator. When I drag it and land in the drag initialize method, the OriginalSource shows me the object from the row, not any indicator that it was this separator. Is there a way to distinguish that the user was dragging this handle and not the row?
Thanks
0
Valerie
Top achievements
Rank 1
answered on 15 Nov 2012, 04:21 PM
oops, sorry, I didn't realize that you had replied to my previous post also. Are you saying that you can't reproduce the problem with the frozen column separator? Are you dragging it from within the grid and not from the header?
0
Nick
Telerik team
answered on 16 Nov 2012, 08:10 AM
Hi Valerie,

I tried it both from the rows and the headers. I am still not able to reproduce it. Unfortunately if the OriginalSource property doesn't tell you if the FrozenColumnsSplitter  is the source of the Drag, it seems there is something wrong either on our side or in your implementation of the DragDrop logic. May I ask you to open a support ticket and send a sample project where the behavior can be observed, so we can tackle the problem directly and provide a solution in the shortest terms? 

Thank you in advance! 

Kind regards,
Nikolay Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Valerie
Top achievements
Rank 1
answered on 17 Nov 2012, 03:31 PM
Thank you. I submitted ticket 630968 which includes a project.
0
Nick
Telerik team
answered on 19 Nov 2012, 08:26 AM
Hi Valerie,

After looking in the project, the problem is that the column splitter propagates the mouse events to the DragDrop manager. I still haven't been able to reproduce the issue outside of your project, but will continue trying and a fix will be provided in the shortest terms.
In the meantime, you can use the following workaround:

private void OnDragInitialize(object sender, DragInitializeEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("In GridViewDragDropBehavior: OnDragInitialize");
    DropIndicationDetails details = new DropIndicationDetails();
    var item = (sender as RadGridView).SelectedItem;
 
    if (item == null)
    {
        e.Cancel = true;
        return;
    }
 
    details.CurrentDraggedItem = item;
 
    IDragPayload dragPayload = DragDropPayloadManager.GeneratePayload(null);
 
    dragPayload.SetData("DraggedData", item);
    dragPayload.SetData("DropDetails", details);
 
    e.Data = dragPayload;
 
    e.DragVisual = new DragVisual()
    {
        Content = details,
        ContentTemplate = this.AssociatedObject.Resources["DraggedItemTemplate"] as DataTemplate
    };
    e.DragVisualOffset = e.RelativeStartPoint;
    e.AllowedEffects = DragDropEffects.All;
}

Hope this helps!  All the best,
Nikolay Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Valerie
Top achievements
Rank 1
answered on 19 Nov 2012, 02:25 PM
Thanks Nikolay. I added the code you suggested, however, it never hits that code (I set a breakpoint) because it seems OnDragInitialize isn't called unless there is a SelectedItem.

As for you not being able to reproduce this outside my project (which actually is the Telerik sample drag/drop project) I found that the problem doesn't always happen. That is, if I keep trying over and over, I can get into a state where it works and continues to work for a while. Then all of a sudden it stops working (ie, gets into the drag code) and continues to not work for a while. I am trying to find a reproducible scenario (such as holding the mouse down longer, or adjusting exactly where my mouse is before I click down, or moving my mouse from the left or right) which makes it sometimes work and sometimes not, but I haven't found one. Perhaps you would see the same in your project if you kept at it for a while.

Thanks, Valerie
0
Nick
Telerik team
answered on 20 Nov 2012, 08:19 AM
Hello Valerie, 

I finally managed to reproduce the issue, however it may prove to be a lot more complex than we would like it to. It seems to be caused by the Fact that the FrozenColumnsSplitter gets the Mouse capture, but since the AllowCapturedDrag property is set the Drag is being executed anyway. 
For the time being you can set the AllowDrag property instead of the AllowCapturedDrag of the GridViewRow, which should fix the issue. We are going to look into the problem and will provide an official fix as soon as possible. 

We are sorry for any inconvenience caused! 

Kind regards,
Nikolay Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Valerie
Top achievements
Rank 1
answered on 21 Nov 2012, 07:08 PM
Hi Nikolay,
I changed the property from AllowCapturedDrag  to AllowDrag. That does fix the frozen column splitter. However now when I drag a row it will only drag (ie get into the OnDragInitialize code) some of the time. What I mean is that sometimes when you drag nothing happens. I try over and over and nothing happens. But then for some unknown reason I try again and now it drags. So it is an intermittent problem. I never saw this problem when I had AllowCapturedDrag set.

Thanks, Valerie


0
Nick
Telerik team
answered on 22 Nov 2012, 08:22 AM
Hi Valerie,

This can happen when you are trying to start the drag from an element of the row that can capture the mouse (Button, TextBox, etc.). Nevertheless, we have fixed the issue and the fix will be available in our internal build and Service pack next week. 

We are sorry for any inconvenience caused! 

All the best,
Nikolay Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
V
Top achievements
Rank 1
answered on 04 Dec 2012, 04:24 PM
I too have the same problem, that Horizontal ScrollBar particpates in the dragdrop. When I drag the scrollbar, scrollbar wont move freely. I am styling radgridview cells but not rows. Can you please tell how to solve this issue?
0
Jay
Top achievements
Rank 1
answered on 15 Dec 2017, 06:14 PM

Not sure how you are doing drag and drop but I solved this problem by checking type of originalsource of mouseeventargs. I am performing drag and drop only when OriginalSource is Datagrid. In case of scrollbar Original source is Thumb.

protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseMove(e);            
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed && e.OriginalSource is DataGrid)
            {                   
                DragDrop.DoDragDrop(this, dragData, DragDropEffects.Copy);
            }
        }

Tags
DragAndDrop
Asked by
Valerie
Top achievements
Rank 1
Answers by
Nick
Telerik team
Valerie
Top achievements
Rank 1
V
Top achievements
Rank 1
Jay
Top achievements
Rank 1
Share this question
or