Search code examples
.netvb.netwinformsdatagridviewtransfer

Transfering Rows Between DataGridViews Across 2 Different Forms In VB.NET


first time posting. So I'm making this program in visual studio 2013 in VB.NET

Lets say I have 2 forms:

Form1 and Form2 and on Form1 I have DataGridView1 and on form 2 I have DataGridView2

Both data grids have the same columns.

How can I on the click event of a button on Form1 Get all the data from DataGridView1 from the row i'm currently focused/selected on to be transferred into DataGridView2 on Form2.

Image of what i'm trying to do. enter image description here

If anyone can help me out with this one it would be much appreciated. Thanks


Solution

  • Thanks everyone for the reply's but I ended up doing this:

    Private Sub searchPartsDataGridView_CellContentClicked(sender As Object, e As DataGridViewCellEventArgs) Handles searchPartsDataGridView.CellContentDoubleClick
        Dim colName As String = searchPartsDataGridView.Columns(e.ColumnIndex).Name()
        Dim rowIndex = searchPartsDataGridView.CurrentRow.Index
        If colName = "ITEMNO" Then
            formPartsRequest.partsRequestItemsDataGridView.Rows.Add(searchPartsDataGridView.Rows(rowIndex).Cells("ITEMNO").Value, searchPartsDataGridView.Rows(rowIndex).Cells("DESC").Value)
        End If
    End Sub
    

    Not sure if this is the best way to do it or if its good coding practice but It seem's to work fine and it suit's my purposes. Thanks