---
title: "Unable to update comboBox from another comboBox"  
description: "Unable to update comboBox from another comboBox"  
author: "Jayden Bell"  
published: 2013-12-18  
updated: 2013-12-18  
canonical: https://www.mindstick.com/forum/1811/unable-to-update-combobox-from-another-combobox  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Unable to update comboBox from another comboBox

```
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](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) the comboBox1 as the tabpage open and then populate the comboBox2 based on the selectedText of comboBox1.

comboBox_SelectedIndexChange runs 2 times when tab changes but [returns null](https://www.mindstick.com/forum/159370/sql-join-returns-null-records-when-there-is-no-data-in-the-database-in-sql-server-why) every times.

**Note:** I have [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) appended [event handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question) as the [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) initializes like,

```
public Form1()    {        InitializeComponent();        tabControl1.Selected += new TabControlEventHandler(tabControl1_Selected);        comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;        table = new DataTable();        s = new Stock();    }
```

## Replies

### Reply by Anonymous User

Hi Jayden,

First there is a bug in

```
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";}
```

code. You override value for datasource in line

temp = Color.Get(text);

I think it should be like:

```
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){    DataTable temp = new DataTable();    string text = comboBox1.SelectedItem.ToString();    selectedColor = Color.Get(text);    comboBox2.DataSource = temp;    comboBox2.DisplayMember = "Color_Name";    comboBox2.ValueMember = "Color_ID";    comboBox2.SelectedItem = selectedColor;}
```

I don't know contents of DataTable so instead of comboBox2.SelectedItem you may need to set SelectedItem, SelectedText or SelectedValue properties of comboBox2.


---

Original Source: https://www.mindstick.com/forum/1811/unable-to-update-combobox-from-another-combobox

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
