Simple question involving list boxes and db

drew4663

Well-known member
Joined
May 3, 2007
Messages
62
Programming Experience
1-3
I am making a program that will allow the user to add a Category, Sub-Category1 and Sub-Category2. I want the user to be able to add their own predefined Categories and Sub-Categories in an options page. Then, when they go to add data to the main form it will do the following:

Category (contains) Carton, Box, Bottle

Sub-Category1 (contains) Eggs, Cake Mix, Soda, Cereal, Baby

Sub-Category2 (contains) 12, 24, Yellow, White, Chocolate, 7-UP, Coke, Pepsi, Frosted Flakes, Cheerios

When the user looks at the form there will be three List Boxes and only List Box1(Category) will be populated when the form loads.
The End User will do the following actions.

EU makes first selection in List box1 and chooses

Bottle

Options in List Box 2 now display

Soda, Baby

EU selects Soda and options in List Box 3 now display

7-UP, Coke and Pepsi




What is the above called? Also, is this done by creating relations? I can search for the how to do it on my own but I'm not sure what direction I should be taking.
 
Yes, it is done by creating relations. Your tables will be as follows:

Category (CategoryID [PK], CategoryName)
Subcategory1 (Subcategory1ID [PK], CategoryID [FK: Category], Subcategory1Name)
Subcategory2 (Subcategory2ID [PK], Subcategory1ID [FK: Subcategory1], Subcategory2Name)

You can query the database and populate three DataTables in a DataSet from the three database tables. You can then bind all three DataTables to your ListBoxes in a master/detail arrangement. The filtering of the second and third ListBoxes will then happen automatically.

Retrieving and Saving Data in Databases
Master/Detail (Parent/Child) Data-binding
 
Back
Top