populating a combo box


how do i populate a combo box and once populated, hwo do i get to know which choice the user picked from the list in the combo box.
Who is Participating?
sirbountyConnect With a Mentor Commented:
combobox1.AddItem "ABC"
combobox1.Additem "DEF"

Now to determine which was chosen:

Private Sub ComboBox1_Click()
Msgbox "You chose " & combobox1.list(combobox1.listindex)
Mayank SAssociate Director - Product EngineeringCommented:
BTW, which language are you on?
Just another variation of what sirBounty has written:

I would trap the
ComboBox1.SelectedIndexChanged event instead of the click event.
and in the selectedIndexChanged event, do something like this:

MessageBox.Show("You chose" + combobox1.selectedValue);


MessageBox.Show("You chose" + ComboBox1.SelectedItem.ToString())
Mayank SAssociate Director - Product EngineeringCommented:
Well, why are we assuming that he is using VB or .NET?
Mayank SAssociate Director - Product EngineeringCommented:
Ok, let's have a go at Java (since we don't know which language you are on, we might as well give you solutions for the ones which we know). Solutions for VB and .NET have already been posted.

Populating a combo-box:

list.add ( yourString ) ;

(you can do that in a loop, changing the values of yourString or using a String array or a Collection)

Getting the value that the use selected:

String selectedValue = list.getSelectedItem () ;


int selectedIndex = list.getSelectedIndex () ;
String selectedItem = list.getItem ( selectedIndex ) ;
All Courses

From novice to tech pro — start learning today.