如果某个选定单元格位于第2行,请在数据网格视图中选择第1行的值
本文关键字:视图 网格 数据网 数据 选择 1行 单元格 2行 于第 如果 | 更新日期: 2023-09-27 18:27:03
好的,所以我有两列,一列叫"id",另一列叫做"note"。
我的计划是,当用户双击ID时,会发生一些事情(包含该ID的网站会在网络浏览器控件中打开)。
然而,如果用户双击注释,它显然无法打开ID为的网站,所以我想做的是,当用户双击注释时,它会选择该行中的"ID"值,并使用该值打开Web浏览器。
有人知道怎么做吗?
tl;dr:我想在所选行中选择名为"id"的单元格
使用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
}
我找到了一个解决方案,我让它选择了整行(无论如何都更干净)然后这个代码将选择第一个选择的单元格(意味着行的第一个单元格)
public void SelectIdCell()
{
favorite_GridView.ClearSelection();
foreach (DataGridViewCell cell in favorite_GridView.CurrentRow.Cells)
{
if (cell.Visible)
{
cell.Selected = true;
return;
}
}
}