1. bind the two datagrids to the same DataTable2. you have to write your own Clone() method by going through DataGrid's Items (or its underlying Table.Rows) and create new DataGridItem's and add them to your new DataGrid
to saucer(思归, MS .NET MVP): The 1:I change the data at runtime,so I can't bind the two datagrids to the same datatable The 2:I will try it,thx
The 1:I change the data at runtime,so I can't bind the two datagrids to the same datatable
The 2:I will try it,thx
其实就是重新绑定DG再刷新......AND OTHERS:
myDt.clone; //复制数据表的架构不复制数据.. myDt.copy; //数据与架构一起复制.
1.利用DataGrid_Source的DataSet复制一个数据模式;
1.利用DataGrid_Source构建一个DataTable,然后再绑定到DataGrid_Target中去;
2.构建时要把DataGrid的items和DataTable的DataRow对应,DataGrid的Cell和DataTable的Cloumn相对应即可。
一段代码仅供参考
ds_target = ds_source.Clone();
for ( int i = 0;i< DataGrid1.Items.Count; i++ )
{
DataRow dr = ds_target.Tables[0].NewRow();
for(int j = 0; j < ds_target.Tables[0].Columns.Count;j++)
{
// Response.Write(DataGrid1.Items[i].Cells[j].Text + "//");
dr[j] = DataGrid1.Items[i].Cells[j].Text; }
ds_target.Tables[0].Rows.Add(dr);
}
success,thank you!