Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter DataGridView

I've searched the internet for a solution for my problem, me and my studygrp is making a datagridview that takes information from a classLibrary. All that works but now we got to filter it but all I can find is by bindingsource but that's not what I was thinking. I just want a simple filter so that you can enter something in a textbox and it shows it on the datagridview if it contains that information. I've tried:

((DataTable)dataGridView1.DataSource).DefaultView.RowFilter = "FromColumn like '%" + textBox1.Text + "%'";

But it doesn't work like I want it to hmmn... anyone that can help?

like image 594
Ra91 Avatar asked Feb 18 '23 14:02

Ra91


1 Answers

Try BindingSource. It provides good extensive facilities of filtering

BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "yourColumnName like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = bs;
like image 109
Sami Avatar answered Feb 21 '23 02:02

Sami