Results 1 to 5 of 5

Thread: Drag and drop on Flexgrid

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Drag and drop on Flexgrid

    Hi, I wonder if anyone can give me some guidance on how to implement drag and drop on a Flexgrid? I want users to be able to Right Click on a cell and drag its contents to another cell.

    I can do the detect of the right mouse click okay and know which cell I am over when I do that.

    How do you detect the 'ondragstart' event?

    How do you detect the 'drop' event?

    How do you know which cell you are over when the drop occurs?

    Is it possible to change the cursor while the dragging is happening?

    Is it possible to highlight each cell as the mouse is dragged over it - so it is easy for the user to see where the 'drop' will occur?

    Thanks for any help.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Drag and drop on Flexgrid

    Actually, to try to get me started ... all I have achieved so far is being able to right click on the flexgrid and start to drag the whole grid. What I want to do is click on a flexgrid and just drag the contents of a cell and drop them on another cell.

    Cheers

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Drag and drop on Flexgrid

    all I have achieved so far is being able to right click on the flexgrid and start to drag the whole grid.
    Set the DragIcon property to a valid icon. This changes the cursor and stops you from dragging the control.
    Set the DragMode property to 0 - vbDragManual
    To start a dragging operation call the Drag method

    VB Code:
    1. Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     If Button = vbRightButton Then
    3.         With Me.MSFlexGrid1
    4.             'set the current cell - it does not change on a rightmouse click
    5.             .Row = .MouseRow
    6.             .Col =.MouseCol
    7.             .Drag vbBeginDrag 'start a drag operation.
    8.             strDragText = .Text 'store contents that will be dropped
    9.         End With
    10.     End If
    11. End Sub

    Is it possible to highlight each cell as the mouse is dragged over it - so it is easy for the user to see where the 'drop' will occur?
    Use the DragOver event

    VB Code:
    1. Private Sub MSFlexGrid1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
    2.     If Source Is Me.MSFlexGrid1 Then
    3.         MSFlexGrid1.Col = MSFlexGrid1.MouseCol
    4.         MSFlexGrid1.Row = MSFlexGrid1.MouseRow
    5.     End If
    6. End Sub

    To capture the Drop Event.

    VB Code:
    1. Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
    2.     If Source Is Me.MSFlexGrid1 Then
    3.         With Me.MSFlexGrid1
    4.             .TextMatrix(.MouseRow, .MouseCol) = strDragText
    5.         End With
    6.     End If
    7. End Sub
    Last edited by brucevde; Feb 22nd, 2007 at 01:26 PM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Drag and drop on Flexgrid

    Thanks very much. I'll give it a go.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Drag and drop on Flexgrid

    Hi, thanks again, have the basic stuff working now. A couple of things I can't get to happen though ...

    How do you get the dragicon to disappear if you are not over a valid target? In my Flexgrid I want users to be able to right click on a cell in Column 0 and only be able to 'Drop' on another cell in Column 0. If they stray over Column 1 I want the 'Drag' icon to disappear.

    With the help of your code ... as I drag I now have cells under the mouse turning a different colour. How can I change them back to white when you move from one cell to the next? I have tried using the 'State' (0 = enter, 1 = leave, 2 = over) but can't get it to work.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width