How do I make the DataGridView show the selected row?

kereberos picture kereberos · Dec 8, 2011 · Viewed 96.3k times · Source

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

In short, I have a textbox that changes the DGV selection based on what is typed into the textbox. When this happens, the selection changes to the matching row.

Unfortunately if the selected row is out of the view, I have to manually scroll down to find the selection. Does anyone know how to force the DGV to show the selected row?

Thanks!

Answer

competent_tech picture competent_tech · Dec 8, 2011

You can set:

dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.SelectedRows[0].Index;

Here is the MSDN documentation on this property.