如果某个选定的单元格在row2中,请在datagridview中选择row1的值

时间:2012-03-08 10:24:08

标签: c# datagridview

好吧,我有两个名为“id”的栏目,另一个名为“note”。

我计划这样做,以便当用户双击ID时会发生某些事情(包含该ID的网站在webbrowser控件中打开)。

但是,如果用户双击该笔记,显然无法打开带有该ID的网站,那么当用户双击一个笔记选择该行中的“id”值时,我想要这样做并用它来打开网页浏览器。

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

tl; dr:我想在所选行中选择名称为“id”的单元格

2 个答案:

答案 0 :(得分: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
    }

答案 1 :(得分:0)

我找到了一个解决方案,我让它选择了整行(无论如何都更干净) 然后此代码将选择第一个选定的单元格(表示行的第一个单元格)

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