I have been dragging on this problem for more than a week. I hope someone can help.
I follow the sample in http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=201079&SiteID=1 to implement the dragdrop function on a databound datagridview.
At first, I used myDataTable.Rows.RemoveAt(dragRowIndex) as in the sample code provided by Mark. However I found the RemoveAt command did not do it's work and an extra record was created each time I use the function. Now I replaced it with Delete as below:
Dim rowItemArray As Object() = myDataTable.Rows(dragRowIndex).ItemArray
Dim row As DataRow = myDataTable.NewRow()
row.ItemArray = rowItemArray
myDataTable.Rows(dragRowIndex).Delete()
myDataTable.Rows.InsertAt(row, dropRowIndex)
It seemed working correctly on the database apart from the database concurrency violation problem I post on another thread: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=263545&SiteID=1.
After using the dragdrop function for a couple of times, I found it stopped working and exit (somehow ) at the first line (i.e. the command creating the rowItemArray) without any error. I set break points at line one and two, the program reached line one but never reach line two. I tried to trace the problem by stepping into the command. I just found the MouseMove event keep on firing. If I press Run, the UI appears and the program is still running as usual. Here is the code in my MouseMove Handler:
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim pt As Point = New Point(e.X, e.Y)
Dim mouseMoveRowIndex As Integer = DGV.HitTest(pt.X, pt.Y).RowIndex
If mouseMoveRowIndex > -1 And mouseMoveRowIndex < DGV.Rows.Count - 1 And dragRowIndex <> mouseMoveRowIndex Then
Dim row As New DataGridViewRow
row = DGV.Rows(dragRowIndex)
DGV.DoDragDrop(row, DragDropEffects.Move)
End If
End If
Any idea what's wrong

Drag & Drop row reordering on Databound DataGridView