Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Visual-Studio
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 20-Sep-10 8:22am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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'
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
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. Smile | :)
 
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. Smile | :)
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 319
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 CPallini 205
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 20 Sep 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100