以新形式显示数据网格中的数据
本文关键字:数据 网格 数据网 显示 新形式 | 更新日期: 2023-09-27 18:20:06
我有一个包含数据的数据网格,当我调用dataGridView1_CellDoubleClick
时,我想将数据网格中的数据填充到表单中
public Product something {get; set;}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e){
int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
something = Podatci.GetproductByID(id);
FrmNewForm a = new FrmNewForm();
a.Show();
从逻辑上讲,当我打开一个新表单时,它是空的
如何从打开的窗体访问文本框等对象
您可以将something
传递给表单的新构造函数,并在那里显示它:
添加到表单:
public FrmNewForm(SomethingClass something) : this()
{
txtSomething1.Text = something.Something1;
// etc.
}
创建时:
FrmNewForm a = new FrmNewForm(something);
// your code
FrmNewForm a = new FrmNewForm();
//do something here the way you want to display the values
a.Show();