【发布时间】:2014-03-12 18:29:10
【问题描述】:
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 也无法正常工作。
这是我正在做的第一个项目,我必须将它提交给大学。
它没有进入我的主要形式。
【问题讨论】:
标签: c# sql winforms datagridview