c# - searching for mulitple columns in a dataGridView -
i have code searching specific column name or column number in datagridview :
string str = kartsearchtxt.text; string value = ""; (int = 0; < datagridview1.rows.count; i++) { value = datagridview1.rows[i].cells[3].value.tostring(); if (value.contains(str) == false) { datagridview1.rows.removeat(i); i--; } } }
i've tried diffrent solutions having "2 loops " searching through columns aswell , didnt work .
how can search through multiple columns ? in advance
use loop this
for (int = datagridview1.rows.count - 1; >= 0; i--) { foreach (datagridviewcolumn column in datagridview1.columns) { if (!column.visible || column.displayindex < 0) continue; value = datagridview1.rows[i].cells[column.displayindex].value.tostring(); if (value.contains(str) == false) { datagridview1.rows.removeat(i); } } }
because when remove row(s) grid, datagridview1.rows
takes new value
Comments
Post a Comment