在激活链接的c#程序中使用cellcontentclick事件
我有一个使用datagridview的程序,其中有7列。其中一列是将从指定位置加载文件的超链接。我使用“cellcontentclick”事件打开文件。我的问题是,当我单击行中的任何其他单元格时,它仍将执行cellcontentclick。只有当特定列在单击时才会执行时,我如何使其如此在激活链接的c#程序中使用cellcontentclick事件,c#,datagridview,hyperlink,C#,Datagridview,Hyperlink,我有一个使用datagridview的程序,其中有7列。其中一列是将从指定位置加载文件的超链接。我使用“cellcontentclick”事件打开文件。我的问题是,当我单击行中的任何其他单元格时,它仍将执行cellcontentclick。只有当特定列在单击时才会执行时,我如何使其如此 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string sourcePath = @"SPECIFIED PATH";
Process.Start(sourcePath + dataGridView1.Rows[e.RowIndex].Cells[5].Value);
}
catch (SqlException e)
{
MessageBox.Show("Error occured: " + e);
}
}
if (e.ColumnIndex == 5 && e.RowIndex >= 0)
{
try
{
string sourcePath = @"PATH";
Process.Start(sourcePath + dataGridView1.Rows[e.RowIndex].Cells[5].Value);
}
catch (SqlException a)
{
MessageBox.Show("Error occured: " + a);
}
}
只检查要查找的列的内部事件处理程序。
其中一个参数(e?)有列信息。知道了!我只需要输入if语句并指定列。谢谢你,叶甫盖尼
if (e.ColumnIndex == 5 && e.RowIndex >= 0)
{
try
{
string sourcePath = @"PATH";
Process.Start(sourcePath + dataGridView1.Rows[e.RowIndex].Cells[5].Value);
}
catch (SqlException a)
{
MessageBox.Show("Error occured: " + a);
}
}
不客气。如果有帮助,请将其标记为答案。