I have a form with 2 datagridviews, I want to know how to properly import from "datagridview1" ONLY the selected rows into the 2nd datagridview "DatagridCopy"?
I want to create a new DataTable from the selected row(s) and make that DataTable the datasource for DatagridCopy.
I keep getting this error:
Additional information: Type of value has a mismatch with column type Couldn't store <8S3501> in t101PARTDataGridViewTextBoxColumn Column. Expected type is DataGridViewTextBoxCell.
DataTable dt = new DataTable();
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
dt.Columns.Add(column.Name, column.CellType); //better to have cell type TextBoxCell.
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
dt.Rows.Add();
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
dt.Rows[i][j] = dataGridView1.SelectedRows[i].Cells[j].Value; //ERROR HERE<-----
}
}
}
BindingSource binding = new BindingSource();
binding.DataSource = dt;
DatagridCopy.DataSource = binding;