Canceling a drag-drop, without allowing selected row to move

Posted by: awbacker on 8 September 2017, 12:33 pm EST

  • Posted 8 September 2017, 12:33 pm EST

    I am having an issue with how to stop drag/drop.  When I drag on certain rows I catch them in the DragStart event and set e.Cancel = true.  This stops the dragging behavior, but since the mouse is still down it actually allows the user to continue to move the 'selected' row by moving the mouse.  This means that they end up over a row that _is_ dragable, and now it starts dragging that one instead of the originally clicked one.

    How do I prevent this behavior?  I want to just cancel the drag and leave the user on that row until they let up the mouse button, or at least not drag the selected row around =)

    Thanks,
    //Andrew
  • Replied 8 September 2017, 12:33 pm EST

    Andrew -

    I am not familiar with a DragStart event.  Where are you finding this?
  • Replied 8 September 2017, 12:33 pm EST

    Ahahahahhaha I am so dumb.

    DragStart is an event that I created for our inherited version of the spread.  It's one of those events that you just want to shoot the .net guys for not including, since everyone asks for it.  It is defined as :

    Public Event DragStart As CancelEventHandler

    And it is fired something like this, from within our own MouseMove event which starts a drag operation :  
        Private Sub FpSpreadCtl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles Me.MouseMove
    If (e.Button = Windows.Forms.MouseButtons.Left) Then
    If (GetRootWorkbook().GetActiveWorkbook().GetColumnHeaderCellFromPixel(e.X, e.Y).Column <> -1) Then Return

    Dim
    cevta As New CancelEventArgs(False)
    RaiseEvent DragStart(Me, cevta)
    If (cevta.Cancel = True) Then
    Return
    End If


    StartDragDrop()
    Me.OnMouseUp(e)
    End If
    End Sub
    I have fixed this issue in a way that is "Good Enough For Now" :)  I have simply changed the body to call OnMouseUp if the user cancels as well as after the drag is initiated. It seems a little odd, since the user still technically has the mouse down and it doesn't show the 'not allowed' icon any more, but it works to stop this issue's worst effects, which was having QA complain =) I don't think they will know this isn't quite right either muahahahaha.  A big confusion traded for a little visual wrong-ness is fair enough!
    Dim cevta As New CancelEventArgs(False)
    RaiseEvent DragStart(Me, cevta)
    If (cevta.Cancel = False) Then
    StartDragDrop()
    End If

    Me
    .OnMouseUp(e)



    If there is any way to fix this so that I can get both the (X) drag icon as well as not have the selection move with the mouse then that would be great.

    //Andrew
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels