Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fill or Filter combobox based on vslue from anothe comobobox

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
US
I have 2 combo boxes. I have a counted by combobox which is populated with a list of users that can cycle count product. My second box comes from the same table and is a list of the warehouses where this users is allowed to cycle count.

I need to be able to update the second combobox (list of warehouse) based on the user selected on the first combobox. This would be a list of warehouse the slected user on the first combobox has access to.

Here is my code so far. The first combobox (user) is populated whe nthe form load. I need to populate the second box based on what is sledcted on te first and refresh second combobox if the selection chnages on the first combobox.

Code:
        private void cmbCountByFill()
        {
            da.SelectCommand = new SqlCommand("SELECT DISTINCT W.USER_NAME, U.DESCRIPTION FROM WAREHOUSE_ACCESS W LEFT OUTER JOIN USER_PROFILE U ON U.USER_NAME = W.USER_NAME WHERE U.CYCLE_COUNT_PREFERENCE = 'Inventory Control'", cs);
            {
                DataTable dt = new DataTable();
                da.Fill(dt);


                cmbCountBy.ValueMember = "USER_NAME";
                cmbCountBy.DisplayMember = "DESCRIPTION";
                cmbCountBy.DataSource = dt;

                cmbCountBy.DropDownStyle = ComboBoxStyle.DropDownList;
                cmbCountBy.AutoCompleteSource = AutoCompleteSource.ListItems;
            }
        }

        private void cmbWarehouseFill()
        {
            da.SelectCommand = new SqlCommand("SELECT DISTINCT A.WAREHOUSE FROM WAREHOUSE_ACCESS A", cs);            
            {
                DataTable dt = new DataTable();
                da.Fill(dt);
                
                cmbWarehouse.ValueMember = "WAREHOUSE";
                cmbWarehouse.DisplayMember = "WAREHOUSE";
                cmbWarehouse.DataSource = dt;
                
                cmbWarehouse.DropDownStyle = ComboBoxStyle.DropDownList;
                cmbWarehouse.AutoCompleteSource = AutoCompleteSource.ListItems;
            }
        }

I'm new to C# so any help with this is appreciated

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top