|
-
Feb 22nd, 2007, 10:53 AM
#1
Thread Starter
Fanatic Member
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.
-
Feb 22nd, 2007, 12:15 PM
#2
Thread Starter
Fanatic Member
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
-
Feb 22nd, 2007, 01:22 PM
#3
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:
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
With Me.MSFlexGrid1
'set the current cell - it does not change on a rightmouse click
.Row = .MouseRow
.Col =.MouseCol
.Drag vbBeginDrag 'start a drag operation.
strDragText = .Text 'store contents that will be dropped
End With
End If
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:
Private Sub MSFlexGrid1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
If Source Is Me.MSFlexGrid1 Then
MSFlexGrid1.Col = MSFlexGrid1.MouseCol
MSFlexGrid1.Row = MSFlexGrid1.MouseRow
End If
End Sub
To capture the Drop Event.
VB Code:
Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
If Source Is Me.MSFlexGrid1 Then
With Me.MSFlexGrid1
.TextMatrix(.MouseRow, .MouseCol) = strDragText
End With
End If
End Sub
Last edited by brucevde; Feb 22nd, 2007 at 01:26 PM.
-
Feb 23rd, 2007, 06:33 AM
#4
Thread Starter
Fanatic Member
Re: Drag and drop on Flexgrid
Thanks very much. I'll give it a go.
-
Feb 23rd, 2007, 07:53 AM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|