我有两种表单form1
和form2
。在form1
中,我从数据库中获取数据并使用此数据填充“DataGridView”。
Customer customer = new Customer();
var allcustomers = from c in dc.GetTable<Customer>() select new GetCustomers { firstname = c.firstname, lastname = c.lastname, mobile = c.mobile , customerid = c.customerid};
customerBindingSource.DataSource = allcustomers;
dataGridView1.DataSource = customerBindingSource;
然后,我通过单击grid
创建事件处理程序方法以获取customerid
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int customer_id = list_customers[e.RowIndex].customerid;
MessageBox.Show((customer_id).ToString());
}
现在,我需要将此customer_id发送到form2
以获取所有信息并显示。
知道我是怎么做到的吗?请帮忙
答案 0 :(得分:1)
您可以在创建第二个表单的实例时传递customer_id
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int customer_id = list_customers[e.RowIndex].customerid;
SecondForm form2 = new SecondForm(customer_id);
}
以第二种形式,您可以在构造函数中检索此值,
public Form_2(string custId)
{
InitializeComponent();
var customerId = custId;
}