1 DataTable dt1 = new DataTable();

             DataTable dt2 = new DataTable();

             //为dt1创建结构

             DataColumn pName = new DataColumn("名称");
pName.DataType = System.Type.GetType("System.String");
DataColumn pCount = new DataColumn("数量");
pCount.DataType = System.Type.GetType("System.Int32");
dt1.Columns.Add(pName); dt1.Columns.Add(pCount);
//添加测试用数据 for (int i = ; i < ; i++)
{
DataRow dr = dt1.NewRow();
dr[pName] = "Name";
dr[pCount] = i;
dt1.Rows.Add(dr);
}
gridControl.DataSource = dt1; //将dt1的结构克隆给dt2
dt2 = dt1.Clone();
for (int i = ; i < ; i++)
{
DataRow dr = dt2.NewRow();
dr = dt1.Rows[i];
//此行提示该行已经属于另一个表
//dt2.Rows.Add(dr);
//换成这种写法是正确的或者可以直接使用dt2.Rows.Add(dt1.Rows[i].ItemArray);
dt2.Rows.Add(dr.ItemArray);
}
gridControl.DataSource = dt2;
gridControl.RefreshDataSource();
05-11 15:36