Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DradDrop between 2 bounded datagridview

$
0
0

Hello

I want to drag and drop rows between 2 datagridview binded to the same table.I want to place a row from datagridview 2 to a certain index row in the datagridview1 because I need the order of the row in the datagridview1.

DragDrop

For example I want to change the position of the row of CMD2 to the first row in datagridview1

Here's my code:

 Private Sub DataGridView1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop

    Dim clientPoint As Point = DataGridView1.PointToClient(New Point(e.X, e.Y))
    Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(clientPoint.X, clientPoint.Y)

    Dim dgvr As DataGridViewRow = DirectCast(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
    Dim celldata As Object() = New Object(dgvr.Cells.Count - 1) {}
    For col As Integer = 0 To dgvr.Cells.Count - 1
        celldata(col) = dgvr.Cells(col).Value
    Next

    Dim row As DataRow = ds_data.Tables(0).NewRow()
    row.ItemArray = celldata
    ds_data.Tables(0).Rows.InsertAt(row, DataGridView1.NewRowIndex)

    dgvr.DataGridView.Rows.Remove(dgvr)
End Sub

Private Sub DataGridView1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragEnter

    If e.Data.GetDataPresent(GetType(DataGridViewRow)) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

Private Sub DataGridView2_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView2.MouseMove
    If e.Button = MouseButtons.Left Then

        Me.DataGridView1.DoDragDrop(Me.DataGridView1.CurrentRow, DragDropEffects.All)
    End If
End Sub

Hope I'm clear

Thanks in advance


Best Regards...Please mark as answer if my post is helpful http://yosr-jemili.blogspot.com


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>