Link to home
Start Free TrialLog in
Avatar of LuckyLucks
LuckyLucks

asked on

displaying the selected text choice in a combobox

Hi,

 This is an ez one and I dont know why I cant get it right. I am looking to display the selected text from  drop down choices in a combobox.How do I do this? Please note I am not using associated values.

Thanks
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You mean something like:

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Label1.Text = ComboBox1.SelectedItem.ToString()
    End Sub


?
Avatar of LuckyLucks
LuckyLucks

ASKER

Not to display in a label's text but in the combo box itself. And this is after the selection is done i,e I select the item and after  a while I want to reset the display portion of the combobox to say "apple"
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi LuckyLucks,

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

ComboBox2.Items.Add(ComboBox1.SelectedItem.ToString())

///do something else?!

End Sub

The above event adds a selected item in ComboBox1 to ComboBox2

Private Sub resetCombo()
ComboBox2.Items.Clear()
ComboBox2.Items.Add("apples")
ComboBox2.SelectedIndex = 0
End Sub

You can call the sub above when you want the box to reset and initialize with apples in the display area.  0 is the first item in the list.  a negative 1 means no selection has been made.

I hope this helps.

gl,
Lucas

Or instead, if you already initialize apple into the box you can use this

ComboBox2.SelectedIndex = 0

to

ComboBox2.SelectedItem = "apple"


gl,
Lucas
was the information I provided any good?

Lucas