If your DataGridView is not bound to a data source, then setting the Visible property to false will hide it:
for (int i = 0; i < dgTest.Rows.Count; i++) { var row = dgTest.Rows[i]; if (row.Cells[0].Value.ToString() == search) { row.Selected = true; row.Visible = true; } else { row.Selected = false; row.Visible = false; } }
(I deleted the "break" command, because even after you find a matching line, you need to continue and hide the other lines.)
If you use a DataBinding, it is not as simple as shown on this page .
stuartd
source share