populating a combo box

hi

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.
KallibaAsked:
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)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
BTW, which language are you on?
0
 
gregasmCommented:
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);

//or

MessageBox.Show("You chose" + ComboBox1.SelectedItem.ToString())
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Well, why are we assuming that he is using VB or .NET?
0
 
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 () ;

OR:

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

From novice to tech pro — start learning today.