Solved

windows forms filling combobox's

Posted on 2004-09-11
2
198 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
ID: 12035595
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
ID: 12035629
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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