forum

Home / DeveloperSection / Forums / Unable to update comboBox from another comboBox

Unable to update comboBox from another comboBox

Jayden Bell 2309 18-Dec-2013
private void tabControl1_Selected(object sender,TabControlEventArgs e)
    {
        if(e.TabPage.Name == tabPage2.Name)
        {
            table =Items.Get();
            comboBox1.DataSource = table;
            comboBox1.DisplayMember = "Item_ID";
        }
    }
   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable temp = new DataTable();
        string text = comboBox1.SelectedItem.ToString();
        temp = Color.Get(text);
        comboBox2.DataSource = temp;
        comboBox2.DisplayMember = "Color_Name";
        comboBox2.ValueMember = "Color_ID";
    }

I am trying to populate the comboBox1 as the tabpage open and then populate the comboBox2 based on the selectedText of comboBox1.

comboBoSelectedIndexChange runs 2 times when tab changes but returns null every times.

Note: I have already appended event handler as the form initializes like,

public Form1()
    {
        InitializeComponent();
        tabControl1.Selected += new TabControlEventHandler(tabControl1_Selected);
        comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
        table = new DataTable();
        s = new Stock();
    }

Updated on 18-Dec-2013

Can you answer this question?


Answer

1 Answers

Liked By