Hi,
I have a datagridview with records completed by datatable dt:
This datatable has 20 columns with 1 identity column
dataGridView1.D ataSource = dt;
I need to solve next problems:
1. Select rows filtered by column[2]
2. Keep these records
3. Add exactly the same records below but update column[2] with different value (so we’ll have twice more records)
I used next code for copying from one datatable to another but stack how to add/update rows
Thanks,
I have a datagridview with records completed by datatable dt:
This datatable has 20 columns with 1 identity column
dataGridView1.D ataSource = dt;
I need to solve next problems:
1. Select rows filtered by column[2]
2. Keep these records
3. Add exactly the same records below but update column[2] with different value (so we’ll have twice more records)
I used next code for copying from one datatable to another but stack how to add/update rows
Code:
DataTable dtSource = ((DataTable)dataGridView1.DataSource);
DataTable dtTarget = new DataTable();
dtTarget = ((DataTable)dataGridView1.DataSource).Clone();
DataRow[] rowsToCopy;
rowsToCopy = ((DataTable)dataGridView1.DataSource).Select("DrawingNo='DM-3012'
");
foreach (DataRow temp in rowsToCopy)
{
dtTarget.ImportRow(temp);
}
dt = dtTarget;
Thanks,