2017-10-20 39 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); 
    } 
} 
相關問題