I need to make a filter like that for a system I'm developing but I can only make it work with a single row but when I try to add more rows and run the program it stops and giveme an error, this is the code I'm using:
public partial class frmconsultamateriaprima : Form
{
DataView view = new DataView();
public frmconsultamateriaprima()
{
InitializeComponent();
}
private void frmconsultamateriaprima_Load(object sender, EventArgs e)
{
DataTable datatable = new DataTable();
SqlConnection con = new SqlConnection(@"Data Source=USER-PC;Initial Catalog=dbpuntodeventa;Integrated Security=True");
con.Open();
datatable.Load(new SqlCommand("select * from materiaprima", con).ExecuteReader());
dataGridView1.DataSource = view = datatable.DefaultView;
con.Close();
}
private void txtfiltro_TextChanged(object sender, EventArgs e)
{
view.RowFilter = (" nombre like '%" + txtfiltro.Text + "%' or id like '%" + txtfiltro.Text + "%'");
if (txtfiltro.Text == "")
view.RowFilter = string.Empty;
}
}