winform2 using sql server 2008
本文关键字:2008 server sql using winform2 | 更新日期: 2023-09-27 17:49:41
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打开了一个子窗体。
子表单的名称是CustomerDetails。在这个表单中,如果我想要更新或删除已经存在的客户,我在CustomerName前面添加了一个按钮。单击该按钮将打开一个名为CustomerRecord的新表单。在这种形式中,我使用了DataGridView,并编写了代码来检索数据库中的数据。
现在我想如果dataGridView1_RowHeaderMouseClick被点击,我想在CustomerDetails表单上获得选中的行。
上面的代码不能工作。
另一个问题是,在dateTimePicker下面,grpGender也不工作。
这是我做的第一个项目,我必须把它作为一个项目提交给大学。
这行不行:
cd.MdiParent = new frmDairyManagementSystem();
MDI父表单必须是顶级表单。然后在其中实例化子元素并将它们添加到mdi集合中。
frmDairyManagementSystem
是父节点,它必须是活动的且可见的。