Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to filter a datagrid in VB 2010 express. I've already made the connection to the datasource and can see the complete db on the grid, but I'm not sure how to filter the grid itself. I have a text box placed that I want to use to enter keywords and then run the filter when Enter is pressed. Help! Thanks, Rich.
Posted

You should search the articles page here on Code Project. There are several good examples.

This one - DataGrid with built in filter[^] is in C#.

This one - A Filter Dialog for a DataGridView[^] is in VB and does much the same thing in a different way.

Have a look round and see if there is something more suited to your scenario, otherwise the two above might give you some ideas.

I have assumed that you meant the DataGridView control as you did not say it was ASP.Net

BTW the search term I used was 'filter datagridview'
 
Share this answer
 
OK, I'm pretty new at this and I don't need anything complex. I'm trying to take small steps. I have a query built that works when I hard code data in it. I would like more flexibility so I created a toolstrip with a textbox for the query. If I could just find out how to write the SQL so it can run the query based on the string in the toolstrip textbox, that would do nicely, I think. I just don't know how to make the SQL look in the toolstrip textbox for the string to search for in the SQL builder.
 
Share this answer
 
After your latest post:

What you need is called a Parameterized Query.

Which is basically the query you currently use but with a special marker in place of the changeable data. The marker gets replaced with whatever the user types into the textbox.

An example[^]. I don't think that this is the best example out there, it is simply the first hit on google from a search on parameterized queries vb.net.

One way to use this would be to hook up to the Leave event of your TextBox. Combining that with the Method used in the example linked to above, in the event handler
VB
private void myTextBox_Leave(object sender, EventArgs e)
{
    ' obviously for your situation you would only need one string here
    DisplayPersonData(myTextBox.Text, someotherstring)
}


If you have problems understanding the link above then please search for yourself. There are loads of good examples out there.

Good Luck. :)

If you need more help, rather than add an answer, click on the 'Add Comment' widget at the bottom of this answer. That way I'll get notified (as it is I only found your second point by accident). Or if you would rather have someone else, start a new question and link to this one. :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900