我正在使用此代码使我的列(从 dataTable 中的数据库中获取)作为链接列
编辑:
void show_visits()
{
try
{
con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sonorepo.mdb");
con.Open();
}
catch (Exception err)
{
MessageBox.Show("Error:" + err);
}
this.pid = Convert.ToInt32(db.GetPatientID(cmbPatientName.SelectedItem.ToString()));
cmd1 = new OleDbCommand("Select Patient_ID,VisitNo,VisitDate,remark from Patient_Visit_Details WHERE Patient_ID=" + pid, con);
dt = new DataTable();
adp1 = new OleDbDataAdapter(cmd1);
adp1.Fill(dt);
this.dataGridViewVisits.DataSource = dt;
foreach (DataGridViewRow row in dataGridViewVisits.Rows)
{
DataGridViewLinkCell linkCell = new DataGridViewLinkCell();
linkCell.Value = row.Cells[2].Value;
row.Cells[2] = linkCell;
}
this.dataGridViewVisits.CellContentClick+=new DataGridViewCellEventHandler(this.CellContentClick);
}
当我单击此列的任何链接(内容链接)时,我正在使用下面的代码打开表单,但事件没有被触发,我在哪里做错了?
private void CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && ((DataGridView)sender).Columns[e.ColumnIndex].GetType() == typeof(DataGridViewLinkColumn))
{
int pid = Convert.ToInt32(dataGridViewVisits.Rows[e.RowIndex].Cells["Patient_ID"].Value);
ViewR viewrepofrm = new ViewR(pid);
viewrepofrm.MdiParent = this.ParentForm;
viewrepofrm.Show();
}
}