Solved

windows forms filling combobox's

Posted on 2004-09-11
2
216 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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