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 !
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 !