Need help on combo box and textbox event

todoink

Member
Joined
Jul 27, 2006
Messages
15
Programming Experience
Beginner
Hello,

I need a code. This is only a simple problem. I have 1 combo box and 1 textbox. The combo box has the ffg. items : 1, 2 and 3. What I want to happen is when I select an item on the combo box, that item will appear on the textbox. For example I've choose 1 on the combo box, then a number 1 will be shown on the textbox. Same thing goes with 2 and 3. Thanks a lot.
 
TextBox1.Text = ComboBox1.SelectedItem.ToString
That will work as long as the ComboBox contains simple values, like strings or numbers. If you've bound data to the ComboBox then each item is a DataRowView so that will not be useful. The "proper" way to do this so it will work in all situations would be:
VB.NET:
myTextBox.Text = myComboBox.GetItemText(myComboBox.SelectedItem)
or just:
VB.NET:
myTextBox.Text = myComboBox.Text
Whatever the case, you have to handle the SelectedIndexChanged or SelectionChangeCommitted event of the ComboBox.
 
Hello,

I need a code. This is only a simple problem. I have 1 combo box and 1 textbox. The combo box has the ffg. items : 1, 2 and 3. What I want to happen is when I select an item on the combo box, that item will appear on the textbox. For example I've choose 1 on the combo box, then a number 1 will be shown on the textbox. Same thing goes with 2 and 3. Thanks a lot.

If they were data bound controls, you would bind them through the same binding context, and all would be simple :)
 
Back
Top