How do i filter in bindingsource
-
i want to filter something like string type in my textbox but my code is not working..how do i fix this
private void button1_Click(object sender, EventArgs e) { bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text"; bindingSource1.Sort = "LASTNAME ASC"; }
-
i want to filter something like string type in my textbox but my code is not working..how do i fix this
private void button1_Click(object sender, EventArgs e) { bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text"; bindingSource1.Sort = "LASTNAME ASC"; }
According to the example on MSDN[^], you'd need to re-assign the bindinsource to the datagridview;
// Filter the items to show contacts who are owners.
BindingSource1.Filter = "LASTNAME='Owner'";// Sort the items on the company name in descending order.
BindingSource1.Sort = "LASTNAME ASC";// Set the data source for dataGridView1 to BindingSource1.
dataGridView1.DataSource = BindingSource1;I are Troll :suss:
-
i want to filter something like string type in my textbox but my code is not working..how do i fix this
private void button1_Click(object sender, EventArgs e) { bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text"; bindingSource1.Sort = "LASTNAME ASC"; }
crisjala wrote:
bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text";
You might also want to pick up a book on beginners C# and work through it. It seems you have no idea how strings work. This line should be closer to
bindingSource1.Filter = @"LASTNAME LIKE% " + textBox1.Text;
though using user input directly without validating it could be considered one of the great sins of programming.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...