Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2007, 09:04 PM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing combobox based on selection

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
selection based on conditions rajesh_css XSLT 3 October 2nd, 2008 08:06 PM
Fill DataGrid based on the selection in combobox drani C# 12 October 11th, 2007 05:41 PM
How to catch mouse selection on a combobox? jeffcflam Pro VB 6 0 May 24th, 2006 07:22 AM
ComboBox Selection Question vtonny1 Access 2 February 11th, 2006 01:14 PM
USER SELECTION FROM A COMBOBOX AxeSess Access VBA 3 February 15th, 2004 06:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.