Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

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.
0
Kalliba
Asked:
Kalliba
  • 3
1 Solution
 
sirbountyCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now