[英]If a certain selected cell is in row2, select value of row1 in datagridview
好了,我有两列,一列称为“ id”,另一列称为“ note”。
我的计划是让用户双击ID时发生一些事情(包含该ID的网站在Web浏览器控件中打开)。
但是,如果用户双击便笺,则显然无法打开带有ID的网站,因此当用户双击便笺时,我想做的就是选择该行中的“ id”值并使用该ID打开网络浏览器。
有人知道如何执行此操作吗?
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.