I have a DataTable bound to a dataGridView using the following code :
dataGridView1.DataSource = ReducedColTable;
At some point i would like to move the selected rows into another Table. So here is the loop :
List<DataGridViewRow> rows = (from DataGridViewRow row in dataGridView1.SelectedRows
where !row.IsNewRow
orderby row.Index
select row).ToList<DataGridViewRow>();
foreach (DataGridViewRow item in rows)
{
DataRow newRow = dtarget.Rows.Add();
newRow.SetField("artiste", item.Cells[0].Value);
newRow.SetField("album", item.Cells[1].Value);
newRow.SetField("song", item.Cells[2].Value);
newRow.SetField("year", item.Cells[3].Value);
newRow.SetField("file_path", item.Cells[4].Value);
newRow.SetField("file_size", item.Cells[5].Value);
dataGridView1.Rows.RemoveAt(item.Index);
}
Ps : I didnt find a way to copy the row into the new table (dtarget) which is declared globally hence the approach col by col.
DataTable dtarget = new DataTable();
My issue is that the last line is removing the row from the DataGridView but not from the original table (ReducedColTable)
Any hint how to achieve this ?
Clone()the original. You can get a DataRow object and copy it to the cloned DataTable.