At the risk of telling you some things you may already know, here goes...
I take it this is for a Windows form, but I am throwing in information about
Webforms, just in case.
On your Windows form you have ComboBoxes, ComboBox1, 2, etc, and a
corresponding TextBoxes, TextBox1, 2, etc.
In a Database table named Items you would have Fields: Category, Item, Price.
In the Form Load event, you would create a DataTable for each ComboBox:
Select * From Items WHERE Category = 1"
Select * From Items WHERE Category = 2"
etc
Use a Command object and a Connection to create the Datatables:
DT1, DT2, etc
For a dropdown box on a Windows form, use the ComboBox.
(For a Webform, use the DropDownList)
In the form Load event, set the Datasource property of each Combo or DDL to
the corresponding Datatable. Then, for the Combo, set the DisplayMember
property to the name of the field you want to display, i.e. Item.
(For a Webform DDL, set DataTextField to same.)
When using a Webform, in addition to setting the Datasource of the DDL, you
must call the DataBind method.
To put the price in the corresponding textbox:
In the SelectedIndexChanged event for the ComboBox (automatically created if
you double click the Combo in design mode), add the following code:
TextBox1.text = DT1.rows(ComboBox1.SelectedIndex).item("Price").to String
For a WebForm the event and code are essentially the same. You would set
AutoPostBack = True for each DDL in the Webform, in order for the user to see
the price upon selection of the item in the list.
www.charlesfarriersoftware.com
"Jeremy Dillinger" wrote:
I have a program setup to pull data from a database. My database table has
things such as (category, Item, price, etc.) In my program I want to have
multiple list boxes that will have a pull down list of different categories.
The category is stored as a number and the item is stored as a string. Also
once the item is picked from the list I would also like to extract the price
corresponding to the chosen item.
This program will be to custom build a computer. So for example. I want one
combo box to have a list of Motherboards(category 3) to choose from and then
once the board is chosen show the price of it next to it. Then below that I
want another combobox that will have a list of Processors(category 4) and
then show the price of that. I would like it to show this for all the
categories out of the database.
How would I go about doing something like
this. Thanks for your help!