Solved

windows forms filling combobox's

Posted on 2004-09-11
2
180 Views
Last Modified: 2010-04-23
I am trying to populate a combobox with a value and text.
i know how to do it in asp but how do you do it on windows forms?

this is what i have so far

 For index = 0 To length - 1 Step 1

            cboProvider.Items.Add(providerData.Rows(index).Item(0))
        Next

what i actually want is  in my combobox my value would be 123 but it would display john
0
Comment
Question by:genesisproject
2 Comments
 
LVL 19

Expert Comment

by:drichards
Comment Utility
The Windows.Forms.ComboBox uses objects in its Items collection.  The ToString() method of the item is what gets diaplayed and the object itself is the item.  Here's a previous answer to this question that gives a code example:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21107318.html
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 250 total points
Comment Utility
Hi there,
if you are using data set or table, bind the two columns to the combo box.
Use DisplayMember and value member property.

cboProvider.DisplayMember = "NameField"
cboProvider.ValueMember = "IDField"

Example: http://www.thescarms.com/dotNet/BindCombobox.asp
-Baan
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

8 Experts available now in Live!

Get 1:1 Help Now