I have a datagridview where i have implemented a search function. By entering characters while datagridview is in focus the first row of the grid with the characters will be selected.
I use:
dtgView[index].Selected = true;
dtgView.FirstDisplayedScrollingRowIndex = index;
The row gets selected, but when i press the up or down arrows to navigate up or down from the selected row, the datagridview starts from row index 0 in the datagrid and not the newly selected row?
Here is the OP's
Original Code / Method
private void dtgView_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue >= 65 && e.KeyValue <= 90 )
{
searchStrings += e.KeyCode;
for (int i = 0; i < dtgView.RowCount; i++)
{
if (dtgView.Rows[i].Cells[0].Value.ToString().
Substring(0, searchStrings.Length) == searchStrings)
{
dtgView.ClearSelection();
dtgView.FirstDisplayedScrollingRowIndex = i;
dtgView.Rows[i].Selected = true;
dtgView.Rows[i].Cells[0].Selected = true;
break;
}
}
}
}