How do I make the DataGridView show the selected row?

后端 未结 9 1224
傲寒
傲寒 2020-12-07 18:17

I need to force the DataGridView to show the selected row.

In short, I have a textbox that changes the DGV select

9条回答
  •  [愿得一人]
    2020-12-07 18:51

    int rowIndex = -1;
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        if (row.Cells[0].Value.ToString().Equals(searchString))
        {
            rowIndex = row.Index;
            break;
        }
    }
    if (rowIndex >= 0)
    {
        dataGridView1.CurrentCell = dataGridView1[visibleColumnIndex, rowIndex];
    }
    

    visibleColumnIndex - selected cell must be visible

提交回复
热议问题