Solved

populating a combo box

Posted on 2004-04-14
7
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …
Introduction to Processes

707 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