【问题标题】:Using cellcontentclick event in a c# program that activates a link在激活链接的 c# 程序中使用 cellcontentclick 事件
【发布时间】:2013-03-17 21:34:00
【问题描述】:

我有一个程序使用包含 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);
        }
    }

【问题讨论】:

    标签: c# datagridview hyperlink


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      知道了!我只需要输入 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);
                  }
              }
      

      【讨论】:

      • 不客气。如果对您有帮助,请将其标记为答案。
      猜你喜欢
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多