I need to create a new form with double combo boxes where listings of the second item combo box depends on the first combo box.
The first combo box is CustomerName and the second is Item.
I've done the whole dragging of the combo boxes into the form and when i tried to run it, it couldnt work as it was intended to.
Help PLease anyone.

Don't know where is your data for combo boxes coming from.
Hope that example helps.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
            string combo1Value;

            List<string> l1 = new List<string>();
            List<string> l2 = new List<string>();
            

        public Form1()
        {
            InitializeComponent();
            l1.Add("List1_item1");
            l1.Add("List1_item2");

            l2.Add("List2_item1");
            l2.Add("List2_item2");
        }

        

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            combo1Value = comboBox1.Items[comboBox1.SelectedIndex].ToString();

            switch(combo1Value)
            {
                case "item1":
                    {
                        comboBox2.Items.Clear();
                        foreach (string s in l1)
                        {
                            comboBox2.Items.Add(s);
                        }

                        break;
                    }
                case "item2":
                    {
                        comboBox2.Items.Clear();
                        foreach (string s in l2)
                        {
                            comboBox2.Items.Add(s);
                        }
                        break;
                    }
                default:
                    MessageBox.Show(comboBox1.Items[comboBox1.SelectedIndex].ToString());
                    break;
            }



        }
    }
}

Items in comboBox1
item1
item2

Its very easy try this. Put this in 1st combo Box's index change event

take the cmbBox1 s selected value in a variable
make a search using that variable value against the source where Items are kept indexed with the CustomerName.
If found then keep on adding in the 2nd comboBoxs list.

Done.

Spoon feeding u with its code is not what am gonna do its very easy do it forurself. Try reading books.

This article has been dead for over six months. Start a new discussion instead.