我的应用程序中有两个数据网格(dataGridView1和dataGridView2)。我正在将选定的项目dataGridView1从dataGridView2. 以下是我目前的做法:
DataTable dt = new DataTable("dt");
DataTable id = new DataTable("id");
try
{
if (dataGridView1.Rows.Count > 0)
{
for (int i = 0; i < dataGridView1.Rows.Count - 0; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null)
{
DataRow row;
DataRow idRow;
row = dt.NewRow();
idRow = id.NewRow();
idRow["id"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
row["id"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
row["Link Name"] = dataGridView1.Rows[i].Cells[2].Value.ToString();
dt.Rows.Add(row);
id.Rows.Add(idRow);
}
}
dataGridView2.DataSource = dt;
}
但是,我还需要能够从dataGridView2. 目前,DataTabledt已绑定,dataGridView2在添加项目后我无法清除它,因为它也会清除dataGridView2.
基本上,我的问题是,有没有办法在不使用的情况下将数据表的内容添加到数据网格datagrid.DataSource?