I've been trying to make a search function for a dataTable. My problem is that the first row of the table is ALWAYS within the filtered rows, even when the boolean column is actually changed to a zero. Here is my search code:
private void buscar()
{
DataTable dataTable;
if (!verTodos)
{
dataTable = DBHelper.Instance.ProductosConStock();
}
else
{
dataTable = DBHelper.Instance.ProductosTodos();
}
dataGridProductos.DataSource = dataTable.DefaultView;
foreach (DataGridViewRow row in dataGridProductos.Rows)
{
if (row.Cells[0].Value.ToString().ToUpper().Contains(txtBusqueda.Text.ToString().ToUpper()) ||
row.Cells[1].Value.ToString().ToUpper().Contains(txtBusqueda.Text.ToString().ToUpper()) ||
row.Cells[2].Value.ToString().ToUpper().Contains(txtBusqueda.Text.ToString().ToUpper()))
{
row.Cells[4].Value = 1;
}
else
{
row.Cells[4].Value = 0;
}
}
dataTable.DefaultView.RowFilter = "mostrar = 1";
}