1 DataTable dt1 = new DataTable(); 2 3 DataTable dt2 = new DataTable(); 4 5 //为dt1创建结构 6 7 DataColumn pName = new DataColumn("名称"); 8 pName.DataType = System.Type.GetType("System.String"); 9 DataColumn pCount = new DataColumn("数量"); 10 pCount.DataType = System.Type.GetType("System.Int32"); 11 dt1.Columns.Add(pName); 12 13 dt1.Columns.Add(pCount); 14 //添加测试用数据 15 16 for (int i = 0; i < 10; i++) 17 { 18 DataRow dr = dt1.NewRow(); 19 dr[pName] = "Name"; 20 dr[pCount] = i; 21 dt1.Rows.Add(dr); 22 } 23 gridControl.DataSource = dt1; 24 25 //将dt1的结构克隆给dt2 26 dt2 = dt1.Clone(); 27 for (int i = 0; i < 2; i++) 28 { 29 DataRow dr = dt2.NewRow(); 30 dr = dt1.Rows[i]; 31 //此行提示该行已经属于另一个表 32 //dt2.Rows.Add(dr); 33 //换成这种写法是正确的或者可以直接使用dt2.Rows.Add(dt1.Rows[i].ItemArray); 34 dt2.Rows.Add(dr.ItemArray); 35 } 36 gridControl.DataSource = dt2; 37 gridControl.RefreshDataSource();