Solved

populating a combo box

Posted on 2004-04-14
7
277 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:Mayank S
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:Mayank S
ID: 10830122
Well, why are we assuming that he is using VB or .NET?
0
 
LVL 30

Expert Comment

by:Mayank S
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …

839 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