2017-10-20 60 views
0

我有在它3个环节一个DataGridView,我希望能够点击的链接,并把它打开,我也利用这个的DataGridView multilpe链接

 private void Dgv_View_Employees_CellContentClick_1(object sender, DataGridViewCellEventArgs e) 
     {    
      if (e.RowIndex >= 0) 
      { 
       DataGridViewRow row = this.Dgv_View_Employees.Rows[e.RowIndex]; 
       string filenametodisplay = row.Cells[8].Value.ToString(); 
       string targetPath = @"C:\root"; 
       string open = System.IO.Path.Combine(targetPath + filenametodisplay); 
       System.Diagnostics.Process.Start(open); 
      } 
     } 

,它工作正常,如果有只有一个链接,问题是,它似乎打开第一个链接并忽略其余部分,我需要更改哪些链接才能打开正确单元格中的链接?

+0

是否有3个单元,在每个小区的链路,或者是否有一个细胞三通?你使用什么类型的datagridviewcell?你试过什么了? –

+0

它是3个单元格,每个都有一个链接,我使用DataGridViewLinkColumns,并用DataGridViewTextBoxColumns尝试它,它们打开链接,但它们只打开第一个链接,无论我点击哪一个链接,我都试图将特定单元格分配给用if()语句将其与某种数字范围进行比较的想法是可变的,但我没有取得任何成功 – Christiaan

回答

2

您可以使用DataGridViewCellEventArgs.ColumnIndex属性获取一个值,该值指示事件发生的单元格的列索引。

例如,如果你在第8列,10和14网址:

if (e.RowIndex >= 0) 
{ 
    if (e.ColumnIndex == 8 || e.ColumnIndex == 10 || e.ColumnIndex == 14) 
    { 
     DataGridViewRow row = this.Dgv_View_Employees.Rows[e.RowIndex]; 
     string filenametodisplay = row.Cells[e.ColumnIndex].Value.ToString(); 
     string targetPath = @"C:\root"; 
     string open = System.IO.Path.Combine(targetPath + filenametodisplay); 
     System.Diagnostics.Process.Start(open); 
    } 
}