简体   繁体   English

使用SQL Server 2008的Winform C#中的MDI表单

[英]Mdi form in winform c# using sql server 2008

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);
    }
}

I want to retrieve the data in my mdi child form but the code does not work. 我想以我的MDI子窗体检索数据,但是代码不起作用。 It does not take any value to my mdi child form 我的mdi子表格没有任何价值

Please help me how i can retrieve data to my mdi child form 请帮助我如何将数据检索到我的MDI子表格中

You can pass data needed by the child form to frmCustomerDetails constructor -- in this case you should define custom constructor in frmCustomerDetails class. 您可以将子窗体所需的数据传递给frmCustomerDetails构造函数-在这种情况下,您应该在frmCustomerDetails类中定义自定义构造函数。 Or, you can create custom Show method in the frmCustomerDetails class and pass the data in the method. 或者,您可以在frmCustomerDetails类中创建自定义Show方法,并在该方法中传递数据。 Inside the frmCustomerDetails class, store the passed data in the private fields and/or bind the data to controls. 在frmCustomerDetails类内部,将传递的数据存储在私有字段中和/或将数据绑定到控件。

So, inside the frmCustomerDetails class it could look like this: 因此,在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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM