Click to See Complete Forum and Search --> : drag and drop rows in 2 datagridview


goldorakiller
12-18-2007, 12:24 PM
Hi everybody !

I have a problem with drag and drop !
I want to make a drag and drop into two datadrigview but i don't know how to move the row that i select in the first datagridview into the second !


I have 2 Datagridview with 4 columns and 32 rows each other.
And I want to move a row of DGV1 (source) into the DVG2 (destination) and i want that the selected row of DVG1 replace the row selected in DVG2.

Here my first little code :

Private clickedRow As DataGridViewRow

Private Sub DataGridView1_MouseDown(ByVal Sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X, e.Y)
clickedRow = DataGridView1.Rows(hit.RowIndex)
DataGridView1.DoDragDrop(clickedRow, DragDropEffects.Copy)
End Sub

Private Sub DataGridView2_DragEnter(ByVal Sender As Object, ByVal e As DragEventArgs) Handles DataGridView2.DragEnter
e.Effect = DragDropEffects.Copy
End Sub

Private Sub DataGridView2_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles DataGridView2.DragDrop
Dim ClientPoint As Point = DataGridView2.PointToClient(New Point(e.X, e.Y))
Dim hit2 As DataGridView.HitTestInfo = DataGridView2.HitTest(ClientPoint.X, ClientPoint.Y)


Dim myType As Type = DataGridView1.Rows.GetType
If hit2.RowIndex <> -1 Then
DataGridView2.Rows.Insert(hit2.RowIndex, e.Data.GetData(myType))
Else
DataGridView2.Rows.Add(e.Data.GetData(myType))
End If
My probleme is here, i can't obtain the row in DVG2

If someone can help me it would be great !
THX in advance !

PS : sorry for my english I'm french !

Hack
12-19-2007, 08:21 AM
Do these help?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=259011&SiteID=1

http://windowsclient.net/blogs/faqs/archive/2006/07/10/how-do-i-perform-drag-and-drop-reorder-of-rows.aspx

Hack
12-19-2007, 08:26 AM
Here (http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms/2006-12/msg00207.html) is another one the I found.

I hope these help.

goldorakiller
12-19-2007, 09:07 AM
Do these help?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=259011&SiteID=1

http://windowsclient.net/blogs/faqs/archive/2006/07/10/how-do-i-perform-drag-and-drop-reorder-of-rows.aspx

I know this two code but doesn't work for me !
The first is for drag and drop a cell not a row (I try this and it's work for cell but not for rows)

The second is in C sharp and when i translate in Vb it doesn't work !

otherwise thx

Hack
12-19-2007, 09:12 AM
Ok, well, I'll keep looking and see what I can find.