Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB SQL DataGridView
I currently have a DataGridView that displays items from a database, and I'm stuck on filtering all these items.
 
I used the query builder to make an SQL statement using
Subject LIKE ? + '%'
and
Topic LIKE ? + '%'
which filters via two textboxes. This works fine, however I'd much rather use Combobox's.
 
What I'm trying to do is use a Combobox for filtering instead of a textbox.
The first Combobox needs to have a list of all the different Subjects in the database, and the second Combobox needs to show all the different topics that are currently shown in the datagridview (So only the topics related to the currently filtered subject are shown)
 
Sorry if this is a little hard to understand, I'd be happy to follow up with any more information if needed.
 
Thanks in advance.
Posted 18-Mar-13 10:08am
Comments
Sergey Alexandrovich Kryukov at 18-Mar-13 15:45pm
   
What did you try so far?
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can implement the following solution
1. Populate both Subject and Topics tables
2. Add both tables to a DataSet
3. Add relationship between Subject and Topics (See the below link)
4. Populate Subject in one Combo
5. Populate Topics in another combo. Now when user select a subject, the topics combo will get filtered automatically.
 

The following link will tell you how to add relationships
http://msdn.microsoft.com/en-us/library/ay82azad(v=vs.80).aspx[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 309
2 BillWoodruff 174
3 /\jmot 160
4 Suraj Sahoo | Coding Passion 160
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 18 Mar 2013
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