使用sql server 2008在winform c#中使用Mdi格式

时间:2014-03-13 12:19:17

标签: c# sql winforms mdichild

frmCustomerDetails cd;
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    try
    {
        DataGridViewRow dr = dataGridView1.SelectedRows[0];
        this.Hide();
        frmDairyManagementSystem cda = new frmDairyManagementSystem();
        //cd.Show();

        if (cd == null || cd.IsDisposed)
        {


            cd = new frmCustomerDetails();
            cd.MdiParent = cda;
            cd.WindowState = FormWindowState.Maximized;
            cd.Show();
        }
        else
            cd.Activate();
        //frmCustomerDetails frm = new frmCustomerDetails();
        //frm.Show();
        cd.txtCustomerID.Text = dr.Cells[0].Value.ToString();
        cd.dateTimePicker1.Text = dr.Cells[1].Value.ToString();
        cd.txtCustomerName.Text = dr.Cells[2].Value.ToString();
        cd.grpGender.Text = dr.Cells[3].Value.ToString();
        cd.txtAddress.Text = dr.Cells[4].Value.ToString();
        cd.txtPhone.Text = dr.Cells[5].Value.ToString();
        cd.txtEmail.Text = dr.Cells[6].Value.ToString();
        cd.txtMobileNo.Text = dr.Cells[7].Value.ToString();
        cd.txtNotes.Text = dr.Cells[8].Value.ToString();
        cd.btnUpdate.Enabled = true;
        cd.btnDelete.Enabled = true;
        cd.btnSave.Enabled = false;
        cd.txtCustomerName.Focus();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

我想在我的mdi子窗体中检索数据,但代码不起作用。它对我的mdi子表格没有任何价值

请帮助我如何将数据检索到我的mdi子表格

1 个答案:

答案 0 :(得分:0)

您可以将子表单所需的数据传递给frmCustomerDetails构造函数 - 在这种情况下,您应该在frmCustomerDetails类中定义自定义构造函数。 或者,您可以在frmCustomerDetails类中创建自定义Show方法,并在方法中传递数据。在frmCustomerDetails类中,将传递的数据存储在私有字段中和/或将数据绑定到控件。

因此,在frmCustomerDetails类中,它看起来像这样:

void Show(DataGridViewRow dr)
{
    //TODO: Store cell values from dr to private fields and/or bind them to controls
    this.MdiParent = cda;
    this.WindowState = FormWindowState.Maximized;
    this.Show();
}