Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a problem with my combo box.
I have 4 combo boxes which are bound to database.

The problem is if I choose one of the list item in 1st combo box then other second , third and forth combo boxex will display the same item.
This is causing me a problem because I am creating a form to calculate a priced item.

First combo box must have different item list from second, third and forth.
For your info too, all these combo boxes are connected to 1 table with column item name.

Please advise or show me how I can make it that if I choose one item list in first combo box then second , third and forth combo box can display with different list items.

I need to solve this issue.

Here is my coding, Please correct my coding if it have a mistake


VB
Private Sub ItemNameComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemNameComboBox.SelectedIndexChanged

connection.ConnectionString = "Data Source=Danawa;Initial Catalog=Store;Integrated Security=True "

connection.Open()
cmd = New SqlCommand("SELECT * FROM ItemIn WHERE ItemName = '" & Me.ItemNameComboBox.Text & "' ", connection)

Dr = cmd.ExecuteReader()
If Dr.Read = False Then
MsgBox("Item Name Is Not Found!!", MsgBoxStyle.Exclamation)
Else
Me.price.Text = Dr("ItemPrice").ToString
End If
Dr.Close()
connection.Close()
Posted
Updated 20-Oct-11 21:51pm
v2
Comments
Dalek Dave 21-Oct-11 3:51am    
Edited for Grammar, Syntax, Spelling and Code Block.

1 solution

1. Collect the items you want to display in the combobox in something that implements an interface of a collection(IList for example) like List (Of Items) or even a Dataset and fill it with your data.
2.In your Combobox there are 3 members of interest:
- DataSource: this is the collection of your items
- DisplayMember: what is shown as text in your ComboBox
- ValueMember: if you want to bind to display the description, but want to query for a Key or something

If you use a dataset, you can write combobox.DisplayMember="table1.desc" and combobox.ValueMember="table1.id"( as far as i remember).

For more information look into "Pro .NET 2.0 Windows forms and custom controls in VB 2005" from Apress, chapter 8. You can also view it on google books.
 
Share this answer
 
v3
Comments
Dalek Dave 21-Oct-11 3:52am    
Good Answer.

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