Solved

populating a combo box

Posted on 2004-04-14
7
270 Views
Last Modified: 2010-04-17
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
Comment
Question by:Kalliba
  • 3
7 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 25 total points
ID: 10822453
combobox1.AddItem "ABC"
combobox1.Additem "DEF"

Now to determine which was chosen:

Private Sub ComboBox1_Click()
Msgbox "You chose " & combobox1.list(combobox1.listindex)
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10822497
BTW, which language are you on?
0
 
LVL 8

Expert Comment

by:gregasm
ID: 10825360
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
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10830122
Well, why are we assuming that he is using VB or .NET?
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10830140
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now