datagridview数据从一种形式转移到另一种形式 [英] datagridview data transfer from one form to other form
本文介绍了datagridview数据从一种形式转移到另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用两种形式,两种形式都有各自的数据网格.我
没有将任何数据网格绑定到任何数据源,但我只是向一个数据网格添加了一些行,并想使用代码将其复制到其他表单数据网格
i am using 2 forms having both of them having separate datagrid. i
did''t bound any datagrid to any datasource but i just added some rows to one datagrid and want to copy it to other form datagrid using the code
RegistrationForm rg = new RegistrationForm();
for (int i = 0; i < this.dataGridView2.Rows.Count-1; i++)
{
string[] values = { this.dataGridView2.Rows[i].Cells ["TestID"].Value.ToString(), this.dataGridView2.Rows[i].Cells["TestName"].Value.ToString(), this.dataGridView2.Rows[i].Cells["Charges"].Value.ToString(), this.dataGridView2.Rows[i].Cells["DeliveryDate"].Value.ToString() ;
}
rg .dataGridView1.Rows.Add(values);//dataGridView is on an other form
his.Close();
此代码在调试器中显示数据已复制,但在datagrid中却不显示.
为什么?
this code shows in debuger that the data is copied but in the datagrid it not displys.
why ?
any sugistion or any alternate code pleas.
推荐答案
为什么不创建数据源并将其与以其他形式存在的DataGridView绑定,而不是添加行?
Why don''t you create a datasource and bind that with the DataGridView present in a different form instead of adding rows?
这篇关于datagridview数据从一种形式转移到另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文