Solved

populating a combo box

Posted on 2004-04-14
7
276 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 130
index Out OF Range Exception error 4 61
Plain Text Editor for iPad 6 75
Advice in Xamarin 21 79
This is about my first experience with programming Arduino.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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