P
Patrick A
All,
Pardon the cross-post.
I've used other (C#) code snippets found around here to try to
implement drag-n-drop in a DataGridView, to give the user a way to
sort the data in the grid.
I'm mostly there - I am able to drag, see the cursor change to drag,
and when I let go, the row I dragged leaves it's original spot.
Problem is, it "drops" into a black hole.
Here's the line I'm trying to "drop" with;
TBL_TimersDataGridView.Rows.Insert(RowIndexOfItemUnderMouseToDrop,
RowToMove)
The full code is below.
Can anyone tell me what I'm doing wrong, or point me to the way to do
this?
Thanks,
Patrick
***************************************************************************
***********************************
Private Sub TBL_TimersDataGridView_DragDrop(ByVal sender As Object,
ByVal e As System.Windows.Forms.DragEventArgs) Handles
TBL_TimersDataGridView.DragDrop
Dim ClientPoint As Point =
TBL_TimersDataGridView.PointToClient(New Point(e.X, e.Y))
RowIndexOfItemUnderMouseToDrop =
TBL_TimersDataGridView.HitTest(ClientPoint.X, ClientPoint.Y).RowIndex
If e.Effect = DragDropEffects.Move Then
Dim RowToMove As DataGridViewRow =
TBL_TimersDataGridView.Rows(RowIndexFromMouseDown) 'Gets row to move.
TBL_TimersDataGridView.Rows.RemoveAt(RowIndexFromMouseDown) 'Removes
the row when you finish drag-drop.
TBL_TimersDataGridView.Rows.Insert(RowIndexOfItemUnderMouseToDrop,
RowToMove) 'Does not work...
End If
End Sub
Pardon the cross-post.
I've used other (C#) code snippets found around here to try to
implement drag-n-drop in a DataGridView, to give the user a way to
sort the data in the grid.
I'm mostly there - I am able to drag, see the cursor change to drag,
and when I let go, the row I dragged leaves it's original spot.
Problem is, it "drops" into a black hole.
Here's the line I'm trying to "drop" with;
TBL_TimersDataGridView.Rows.Insert(RowIndexOfItemUnderMouseToDrop,
RowToMove)
The full code is below.
Can anyone tell me what I'm doing wrong, or point me to the way to do
this?
Thanks,
Patrick
***************************************************************************
***********************************
Private Sub TBL_TimersDataGridView_DragDrop(ByVal sender As Object,
ByVal e As System.Windows.Forms.DragEventArgs) Handles
TBL_TimersDataGridView.DragDrop
Dim ClientPoint As Point =
TBL_TimersDataGridView.PointToClient(New Point(e.X, e.Y))
RowIndexOfItemUnderMouseToDrop =
TBL_TimersDataGridView.HitTest(ClientPoint.X, ClientPoint.Y).RowIndex
If e.Effect = DragDropEffects.Move Then
Dim RowToMove As DataGridViewRow =
TBL_TimersDataGridView.Rows(RowIndexFromMouseDown) 'Gets row to move.
TBL_TimersDataGridView.Rows.RemoveAt(RowIndexFromMouseDown) 'Removes
the row when you finish drag-drop.
TBL_TimersDataGridView.Rows.Insert(RowIndexOfItemUnderMouseToDrop,
RowToMove) 'Does not work...
End If
End Sub