c# - set selected row datagridview by cell's value -
how set selected row on datagridview
string?
example..
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
Post a Comment