Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts,

I am trying to copy selected rows of one datagridview to another. I couldn't accomplish it. Could you please help me?

Here is what I tried so far. But didn't work
VB
Dim dt As New DataTable
     DataGridView2.Columns.Add("ICITEM", "Item")
     DataGridView2.Columns.Add("ICDSC1", "Desc1")
     DataGridView2.Columns.Add("ICDSC2", "Desc2")
     DataGridView2.Columns.Add("ICDSC3", "Desc3")
     DataGridView2.Columns.Add("ICTRLN", "Tireline")
     DataGridView2.Columns.Add("I001001", "Manufacturer")



     For Each dgvRow As DataGridViewRow In dgvShow.SelectedRows
       Dim dgvNewRow As New DataGridViewRow
       For i As Integer = 1 To dgvShow.Columns.Count - 1
         dgvNewRow.CreateCells(DataGridView2)
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICITEM").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICDSC1").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICDSC2").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICDSC3").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICTRLN").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("I001001").Value
         DataGridView2.Rows.Add(dgvNewRow)
       Next


     Next
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900