C# 使用sql server 2008的winform2
在我的主窗体中,我使用Mdi打开了一个子窗体 子窗体的名称为CustomerDetails。在这个表单中,如果我想更新或删除已经存在的客户,我已经在CustomerName前面添加了一个按钮。单击该按钮将打开一个名为CustomerRecord的新表单。在这种形式下,我使用了DataGridView,并编写了从数据库检索数据的代码 现在,我希望如果单击dataGridView1_RowHeaderMouseClick,我希望在CustomerDetails表单上获取所选行 上述代码不起作用 另一个问题是,在dateTimePicker下面,grpGender也不工作 这是我的第一个项目,我正在做的一个项目,我必须提交给大学C# 使用sql server 2008的winform2,c#,sql,winforms,datagridview,C#,Sql,Winforms,Datagridview,在我的主窗体中,我使用Mdi打开了一个子窗体 子窗体的名称为CustomerDetails。在这个表单中,如果我想更新或删除已经存在的客户,我已经在CustomerName前面添加了一个按钮。单击该按钮将打开一个名为CustomerRecord的新表单。在这种形式下,我使用了DataGridView,并编写了从数据库检索数据的代码 现在,我希望如果单击dataGridView1_RowHeaderMouseClick,我希望在CustomerDetails表单上获取所选行 上述代码不起作用 另一
它没有进入我的主窗体。这行行不通:
frmCustomerDetails cd;
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
DataGridViewRow dr = dataGridView1.SelectedRows[0];
this.Hide();
if (cd == null || cd.IsDisposed)
{
cd = new frmCustomerDetails();
cd.MdiParent = new frmDairyManagementSystem();
cd.WindowState = FormWindowState.Maximized;
cd.Show();
}
else
cd.Activate();
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集合中
如果frmDairyManagementSystem
是父级,则它必须处于活动状态且可见
cd.MdiParent = new frmDairyManagementSystem();