I need to force the DataGridView
to show the selected row
.
In short, I have a textbox
that changes the DGV
select
This one scrolls to the selected row without put it on top.
dataGridView1.CurrentCell = dataGridView1.Rows[index].Cells[0];
// This works, it's case sensitive and finds the first occurrence of search
private bool FindInGrid(string search)
{
bool results = false;
foreach (DataGridViewRow row in dgvData.Rows)
{
if (row.DataBoundItem != null)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value.ToString().Contains(search))
{
dgvData.CurrentCell = cell;
dgvData.FirstDisplayedScrollingRowIndex = cell.RowIndex;
results = true;
break;
}
if (results == true)
break;
}
if (results == true)
break;
}
}
return results;
}
Just put that line after the selecting the row:
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.SelectedRows[0].Index;