2012-03-08 52 views
0

好吧,我有两列一个叫做“id”,另一个叫做“note”。如果某个选定的单元格在第2行,请在datagridview中选择第1行的值

我的计划是,当用户双击ID时,会发生一些事情(包含该ID的网站将在Web浏览器控件中打开)。

但是,如果用户双击笔记,它显然不能打开带有ID的网站,所以当用户双击某个笔记时它会选择'id'值行,并用它来打开网页浏览器。

任何人都有任何线索如何做到这一点?

TL;博士:我想选择的行

+0

它是两行还是两列?以及你如何处理id的双击?请张贴一些代码 – V4Vendetta 2012-03-08 10:29:19

+0

两栏对不起 – user1071461 2012-03-08 10:29:49

回答

0

使用CellClick或DoubleClick事件中选择名为“身份证”细胞。

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 
    { 
     int row = e.RowIndex; 
     int column = e.ColumnIndex; 

     //using DataGridview or DataSource with the row or column indexes to get the ID 
    } 
0

我发现了一个解决方案,我使它选择整行代替(这是更干净反正) 和,然后该代码将选择所述第一选择的小区(意味着行的第一小区)

public void SelectIdCell() 
    { 
     favorite_GridView.ClearSelection(); 
     foreach (DataGridViewCell cell in favorite_GridView.CurrentRow.Cells) 
     { 
      if (cell.Visible) 
      { 
       cell.Selected = true; 
       return; 
      } 
     } 
    } 
相关问题