我使用这个代码,以使我的专栏(取从DataTable中的数据库)作为linkcolumndatagridview的链接cellcontent点击不工作
编辑:
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();
}
}
错误或输出在哪里? –
@CarlosLanderas我没有收到任何错误,只是当我点击单元格内容链接'ViewR'表单没有得到显示,应该根据需要显示 – Durga
CellContentClick实际上是在事件中定义的调用? –