我有一个包含数据的数据网格,当我调用dataGridView1_CellDoubleClick
时,我想将数据从datagrif填充到表单中。有一个代码:
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();
并且逻辑上当我打开一个新表格时它是空的
如何从打开的表单中访问文本框等对象
答案 0 :(得分:0)
// your code
FrmNewForm a = new FrmNewForm();
//do something here the way you want to display the values
a.Show();
答案 1 :(得分:0)
您可以将something
传递给表单的新构造函数并在那里显示:
添加到表单:
public FrmNewForm(SomethingClass something) : this()
{
txtSomething1.Text = something.Something1;
// etc.
}
创建时:
FrmNewForm a = new FrmNewForm(something);