我使用這個代碼,以使我的專欄(取從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實際上是在事件中定義的調用? –