2014-03-13 57 views
0
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子窗體Winform c#中使用sql server的Mdi窗體2008

請幫助我如何我可以檢索數據,我的MDI子窗體

回答

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