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. <br><br>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 =) <br><br>Thanks,<br>//Andrew<br>
  • Replied 8 September 2017, 12:33 pm EST

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

    Ahahahahhaha I am so dumb.<br><br>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 : <br><br>Public Event DragStart As CancelEventHandler<br><br>And it is fired something like this, from within our own MouseMove event which starts a drag operation :  <pre class="coloredcode"> <span class="kwd">Private Sub</span> FpSpreadCtl_MouseMove(<span class="kwd">ByVal</span> sender <span class="kwd">As Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.Windows.Forms.MouseEventArgs) _
    <span class="kwd">Handles Me</span>.MouseMove
    <span class="kwd">If</span> (e.Button = Windows.Forms.MouseButtons.Left) <span class="kwd">Then</span>
    <span class="kwd">If</span> (GetRootWorkbook().GetActiveWorkbook().GetColumnHeaderCellFromPixel(e.X, e.Y).Column <> -1) <span class="kwd">Then Return

    Dim</span> cevta <span class="kwd">As New</span> CancelEventArgs(<span class="kwd">False</span>)
    <span class="kwd">RaiseEvent</span> DragStart(<span class="kwd">Me</span>, cevta)
    <span class="kwd">If</span> (cevta.Cancel = <span class="kwd">True</span>) <span class="kwd">Then</span>
    <span class="kwd">Return
    End If</span>

    StartDragDrop()
    <span class="kwd">Me</span>.OnMouseUp(e)
    <span class="kwd">End If
    End Sub</span></pre>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!<br><pre class="coloredcode"><span class="kwd">Dim</span> cevta <span class="kwd">As New</span> CancelEventArgs(<span class="kwd">False</span>)
    <span class="kwd">RaiseEvent</span> DragStart(<span class="kwd">Me</span>, cevta)
    <span class="kwd">If</span> (cevta.Cancel = <span class="kwd">False</span>) <span class="kwd">Then</span>
    StartDragDrop()
    <span class="kwd">End If

    Me</span>.OnMouseUp(e)<br><br></pre>

    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