[RESOLVED] Drag & Drop MSFlexGrid (Again)
Alright, this time I'm wondering why do I see people drag drop to several flex grids and not one.
I just wish to move a row when the first column (0) is clicked and held. Then you can move it up/down and all around (vertical) within it's MSFlexGrid Atmosphere.
I know I would need to use a mousedown thinger but is there any code I can be pointed too if ya'll have dealt with this before.
Much thanks!
Re: Drag & Drop MSFlexGrid (Again)
Re: Drag & Drop MSFlexGrid (Again)
Moving the row vertically would be fairly straightforward, but I don't see how you can move a row horizontally.
To drag the row vertically you'd need to invoke a drag event on .mousedown (if .mousecol=0) then respond to the .dragdrop event. I would suggest adding a row first at the new location (using .additem), populating it with data from the old row cell by cell, then removing the old row using .removeitem.
Re: Drag & Drop MSFlexGrid (Again)
Moving rows within a FlexGrid is pretty straight forward. Using Drag and Drop is not required but since that is what you asked about. Make sure you set the DragIcon property of the grid to a valid icon or cursor.
VB Code:
Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
If Source Is Me.MSFlexGrid1 Then
Dim strTemp As String
With Me.MSFlexGrid1
'make sure all columns are selected
'required for Clip propertye
.Col = 0: .ColSel = .Cols - 1
strTemp = .Clip 'save the data in the selected row
.RemoveItem .Row
.AddItem strTemp, .MouseRow + 1 'moves row after
End With
End If
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton And Me.MSFlexGrid1.MouseCol = 0 Then
Me.MSFlexGrid1.Drag vbBeginDrag
Me.MSFlexGrid1.Row = Me.MSFlexGrid1.MouseRow
End If
End Sub
Re: Drag & Drop MSFlexGrid (Again)
The Code worked great! Props for all.
Re: [RESOLVED] Drag & Drop MSFlexGrid (Again)
what if we have to update the row position in the table in access database after drag and drop in msflexgrid?
Re: [RESOLVED] Drag & Drop MSFlexGrid (Again)
There's no guaranteed default position in a database. The recordset you get from the database is dependent on the Order By clause if there is one, or the database code itself if there isn't one.
Re: [RESOLVED] Drag & Drop MSFlexGrid (Again)
This code is amazing!!!
Futher, while dragging and dropping, is it possible to highlight the source row and current row (where the mouse is) for better visibility.