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

我想以我的MDI子窗體檢索數據,但是代碼不起作用。 我的mdi子表格沒有任何價值

請幫助我如何將數據檢索到我的MDI子表格中

您可以將子窗體所需的數據傳遞給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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM