嵌套Datagridview窗口的实现形成c#?

时间:2014-02-23 19:29:19

标签: c# winforms datagridview

在另一个内部实现datagrid时,我的方案是

Datagridview1将保留DepartmentID列& DeptName

还有一个buttonColumn Expand列,on_click添加了一个文本列Employee,并EmployeeEmployeeIdName来自Datagridview2

的展示

代码是:

int count =0;

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        int rowIndex = dataGridView1.CurrentRow.Index;

        if (dataGridView1.Columns.Contains("Expand") && e.ColumnIndex == dataGridView1.Columns["Expand"].Index)
        {
            if (count % 2 == 0)//for even count show the datagrid2 else hide
            {
                var d = dataGridView1.Rows[rowIndex].DataBoundItem as Test.Departments;

                dataGridView2.DataSource = Test.EmployeeDataaccessLayer.GetAllEmployeesByDepartment(d.DeptId);
                AddemployeeColumns();
               /* foreach (DataGridViewRow r in dataGridView2.Rows)
                {
                    int index = r.Index;
                    var dd = dataGridView2.Rows[index].DataBoundItem as Test.Employee;
                    dataGridView1["Employee", rowIndex].Value = dd;
                }*/ This part to be correct
                count++;
            }
            else 
            {
                dataGridView2.Visible = false;
                count++;
            }


    } 

所以我基本上想要将DatagridView2添加到显示员工详细信息的单元格Employee。在我们绑定子网格的Asp.net中更容易,但在windows窗体中如何实现它?

0 个答案:

没有答案