我想将数据从 DataGridView 传输到另一个,这是我的代码示例:
private void btnShow(object sender, EventArgs e)
{
DataTable dtr = new DataTable();
dtr.Columns.Add(new DataColumn("Name", typeof(string)));
dtr.Columns.Add(new DataColumn("Label", typeof(string)));
dtr.Columns.Add(new DataColumn("Domain", typeof(string)));
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataRow erow = dtr.NewRow();
erow[0] = dataGridView1.Rows[i].Cells[0].Value.ToString();
erow[1] = dataGridView1.Rows[i].Cells[1].Value.ToString();
erow[2] = dataGridView1.Rows[i].Cells[2].Value.ToString();
dtr.Rows.Add(erow);
}
dataGridView2.DataSource = dtr;
}
我仍然NullReferenceException
在 11 号线接收。