Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am developing Windows application (environment: Visual Studio 2010 and C#)
I use a datagridview with records completed by datatable dt:

dataGridView1.DataSource = dt;

This datatable has 20 columns with 1 identity column - column[0] = autonumber, and column[1] called “RecordChecked” implemented as Boolean (checkbox).

I need to solve next problems:

1. Select rows filtered by column[2] (in code example: DrawingNo='DM-3012');
2. Keep these records
3. Add exactly the same records below existing but update column[2] with different value like DrawingNo='DM-3013' (so we’ll have twice more records)

I started from copying records from one datatable into another (see code below) – this code works ok, but then stacked how to add copied records below existing and then update them:

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,
Posted

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