Still trying to re-arrange rows in my datagridview using mouse.
I have found this code online.
When ran it deletes the row that I select to move, but does not insert it in the new location.
Any advise?
Private Sub SkillGrid_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SkillGrid.DragDrop
Dim p As Point = SkillGrid.PointToClient(New Point(e.X, e.Y))
Dim newRow As DataGridViewRow = SkillGrid.Rows(SkillGrid.HitTest(p.X, p.Y).RowIndex)
'gets new row info
If newRow.Index >= 0 And newRow.Index < SkillGrid.Rows.Count Then
Dim oldRow As DataGridViewRow = DirectCast(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
'gets dropped row info
If newRow.Index <> oldRow.Index Then
'if the two rows aren't the same it inserts dropped row
SkillGrid.Rows.RemoveAt(oldRow.Index)
SkillGrid.Rows.Insert(oldRow.Index, oldRow)
End If
End If
End Sub
Private Sub SkillGrid_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SkillGrid.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub SkillGrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SkillGrid.MouseDown
If e.Button = MouseButtons.Left Then
Dim info As DataGridView.HitTestInfo = SkillGrid.HitTest(e.X, e.Y)
If info.RowIndex >= 0 Then
Dim view As DataGridViewRow = DirectCast(SkillGrid.Rows(info.RowIndex), DataGridViewRow)
If view IsNot Nothing Then
SkillGrid.DoDragDrop(view, DragDropEffects.Copy)
End If
End If
End If
End Sub
thanks!