Copy Row from one DataGridView to another

First, copy the schema of the table you want to copy, to the new table

Dim dtTable As DataTable

Dim dtTableNew As DataTable

Dim oDataRow As DataRow

 

dtTable =

Me.dgPayPalPayments.DataSource

dtTableNew = dtTable.Clone
dtTableNew.Clear()
oDataRow = dtTable.Rows(

Me.dgPayPalPayments.CurrentRow.Index)

dtTableNew.ImportRow(oDataRow)

Me.dgAssignIOPayments.DataSource = dtTableNew

 
For this case, I wanted the user to select a row, copy that to a holding area, where the user will then
select from another data grid to merge data entries in a controlled environment.
 
 
==========================================
dim newTable as new dataTable
newtable=originalTable.Clone

after that, using ImportRow you can copy the rows you want
For n As Integer = 0 To originalTable.Rows.Count – 1

newtable.ImportRow(originalTable.Rows(n))

Next

 
if you were to use the newTable.AddRow, you might just get the following error:
Rows cannot be programmatically added to the DataGridView’s rows collection when the control is data-bound. 
Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s