1

我有一个程序使用包含 7 列的 datagridview。其中一列是一个超链接,它将从指定位置加载文件。我使用“cellcontentclick”事件打开文件。我的问题是,当我单击该行中的任何其他单元格时,它仍会执行 cellcontentclick。只有当单击该特定列时才会执行,我该如何做到这一点?

        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);
        }
    }
4

2 回答 2

2

仅检查您要查找的列的内部事件处理程序。参数之一(e?)具有列信息。

于 2013-03-27T17:11:20.380 回答
1

知道了!我只需要输入 if 语句并指定列。谢谢,evgenyl。

        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);
            }
        }
于 2013-03-27T17:22:19.850 回答