c# - set selected row datagridview by cell's value -


how set selected row on datagridview string?

example..

enter image description here

when form_loaded...i want datagridview cell "lsn" selected

so if have string text = "lsn"

then table's row cell value "lsn" selected..

i use datagridview1.rows[3].selected = true; set selected row in datagridview..

but how can if dont know row's index , know string ?

you have iterate through each row of datagridview until find value want. can select row , break out of loop.

foreach(datagridviewrow row in datagridview1.rows) {     // 0 column index     if (row.cells[0].value.tostring().equals("lsn"))     {         row.selected = true;         break;     } } 

i haven't tested example should give right idea.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -