Mdi表单在winformc#中使用sql server 2008
本文关键字:sql server 2008 表单 winformc# Mdi | 更新日期: 2023-09-27 17:49:54
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();
}