Using values in combox in windows application

Posted on 2006-05-05
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 69

    Expert Comment

    by:Éric Moreau
    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

           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

    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:

    Accepted Solution

    PAQed with points refunded (125)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    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…
    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    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…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now