Selecting a row in DataGridView programmatically

Nagendra picture Nagendra · Jun 7, 2011 · Viewed 205.4k times · Source

How can I select a particular range of rows in a DataGridView programmatically at runtime?

Answer

Christoph Fink picture Christoph Fink · Jun 7, 2011

Not tested, but I think you can do the following:

dataGrid.Rows[index].Selected = true;

or you could do the following (but again: not tested):

dataGrid.SelectedRows.Clear();
foreach(DataGridViewRow row in dataGrid.Rows)
{
    if(YOUR CONDITION)
       row.Selected = true;
}