Windows form application. C# 4.0.
Basically I have two datagridviews dgv1 and dgv2. One displays the table correctly. I want to select and clone some rows from dgv1 to dgv2 by clicking on the cells in dgv1.
But the second one doesn’t show data at all.
DataTable dt = new DataTable();
dgv2.AutoGenerateColumns = true;
private void btnAdd_Click(object sender, EventArgs e)
{
DataRowView currentDataRowView = (DataRowView)dgv1.CurrentRow.DataBoundItem;
DataRow row = currentDataRowView.Row;
// add row
dt.ImportRow(row);
dgv2.DataSource = dt;
}
In debug mode, what I found is that
?dt.Rows.Count
1
?dt.Columns.Count
0
?dgv2.AutoGenerateColumns
true
Thanks for advice.
You must create your columns or copy the schema from another table!