I have two comboboxes. One has items I input because there are only 4 choices to choose from. Combobox 2 depends on what is selected on combobox one, but I don't know how to filter out combobox 2 based on what is selected on combobox 1.
Here is what I have:
Food_ComponentsCombobox has the items Milk, Meat, Fruits/Veg., and Grains/Breads
Food_Items_as_PurchasedCombobox is linked to a database that contains the columns Food Components and Food Items as Purchased plus some other stuff.
If I choose Milk in Food ComponentsCombobx, it should populate the Food_Items_as_PurchasedCombobox with only those food items that are milk.
I feel like I am going in the right direction, but I can't figure out the code that specifies I just want the Food Items the user selects.
This is my code and I advice that it is not working:
Private Sub Food_ComponentsComboBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Food_ComponentsComboBox.Click
If Food_ComponentsComboBox.SelectedIndex = 1 Then
Food_Item_as_PurchasedComboBox.Items.Clear()
With Me.Food_Item_as_PurchasedComboBox
.Items.Clear()
.DataBindings.Add("Milk", Me.USDABindingSource, "Food Components", True)
.DataSource = Me.USDABindingSource
.DisplayMember = "Food Item as Purchased"
.ValueMember = "Food Components"
End With
End If
When I run this I get a message "Cannot bind the property "Milk" on the target control" and it points to Food Components on the .Databindings.Add line. I know I'm doing this wrong, but I don't know how to make this work. Again, I need for the user to choose from 4 items on combobox 1. Depending on the item chosen, combobox2 should populate itself with only the items related to the item chosen. Can anyone help? I'd really appreciate it. Thanks!
http://www.galleons.org