2012-11-16 39 views
0

在我的c#(VS2008)应用程序中,我有2个winforms。在Form1中,有一个DataGridView显示“Employee”对象列表。这个datagridview是绑定到EmployeeList BindingSource的数据。在Form2中,控件绑定到Employee bindingsource。以另一种形式编辑Datagridview行项目(Master-Detail)

我可以将Form2中的Employee添加到Form1中的EmployeeList中。我想要的是每当我在datagridview中双击时,Form2将打开选定的员工数据。然后更新的数据将发回到Form1 datagridview。但是,DataGridview不会从Form2更新。

这是什么技术。

预先感谢。 SKPaul。

+2

向我们展示您迄今为止所做的工作 – JWiley

回答

0

没有任何已发布的代码,我们将无法帮助任何特定的问题,但是这是通用的,你可以尝试一下:

在Form1

public void UpdateEmployee(Employee emp) 
{ 
    //update whatever info for that employee 
} 


private void dataGridView1_CellClick(object sender, 
    DataGridViewCellEventArgs e) 
{ 
     DataGridViewCell selectedEmployeeCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; //Get whatever data you're sending from this to the new form 

     Employee tempEmployee = getEmployee(selectedEmployeeCell); 

     Form2 updateEmp = new Form2(tempEmployee, this); 
     updateEmp.showDialog(); 
} 

在窗体2

public Form2(Employee emp, Form1 parent) 
    { 
     //blah blah blah 
    } 

private void UpdateEmployee(Employee emp) 
{ 
    parent.UpdateEmployee(emp); 
}  
0

我尽量避免使用具有网格视图的向导数据源。我会手动编写网格,然后使用第一个网格的编辑行中的按钮将URL中的变量传递到第二个网格。或者在你的情况下,也许是第一个网格的选定行事件。

相关问题