Using values in combox in windows application

Posted on 2006-05-05
Medium Priority
Last Modified: 2010-04-23
I'm writing a windows application in VB.NET.  I'm using a combobox to display text, but I want to store a numeric value with each line.  When an item is selected, I want to be able to retrieve the numeric value.  I know how to do this in a web application but it appears to be totally different in windows apps.  This was fairly easy to do in VB6 but I can't figure out how to do it in VB.NET.  Would appreciate any help.
Question by:stephenkobrien
LVL 70

Expert Comment

by:Éric Moreau
ID: 16616560
Hi stephenkobrien,

Is your combobox bound to a source?

You normally bind the DisplayMember (value that the user will see) and the ValueMember (your value accessible using SelectedValue).

LVL 17

Expert Comment

ID: 16616755
       Dim dsDataset As New DataSet
        Dim drNewRow As DataRow

        drNewRow = dsDataset.Tables(0).NewRow

        drNewRow.Item("TheDisplayText") = "Item #1"
        drNewRow.Item("TheValue") = 1

        cboComboBox.DisplayMember = "TheDisplayText"
        cboComboBox.ValueMember = "TheValue"
        cboComboBox.DataSource = dsDataset.Tables(0)

Author Comment

ID: 16617190
Actually, I found the answer at msdn.  You need to create a class that exposes public properties that are assigned to the DisplayMember and ValueMember properties of the control.  See the link: http://msdn2.microsoft.com/en-us/library/system.windows.forms.listcontrol.valuemember.aspx

Accepted Solution

CetusMOD earned 0 total points
ID: 16814766
PAQed with points refunded (125)

Community Support Moderator

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

809 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