What is the equivalent to the following ?

Posted on 2005-04-12
Last Modified: 2010-04-23


In the Web applications, we have

DropDownList1.Items.Add(New ListItem("Kishore","20")) //Key - value

What is the equivalent in Windows applications for combo box ?

ComboBox1.Items.Add(---------------------------------)  //Want for Key-Value

Question by:kishore_peddi
    LVL 12

    Accepted Solution

    I don't know too much about Key properties in combobox... but I think this is probably the nearest to it...

    An example: (pulled from the help file)
    Dim USStates As New ArrayList()

    USStates.Add(New USState("Washington", "WA"))
    USStates.Add(New USState("West Virginia", "WV"))
    USStates.Add(New USState("Wisconsin", "WI"))
    USStates.Add(New USState("Wyoming", "WY"))

    ListBox1.DataSource = USStates
    ListBox1.DisplayMember = "LongName"
    ListBox1.ValueMember = "ShortName"
    LVL 4

    Expert Comment

    There is no direct equivalent to the key/value in the ComboBox, however, combobox displays whatever you have in the object's item ".ToString" value:

    private class cbItem
    public [Key] as string
    Public [Value] as string
    public sub New([Key] as string,[Value] as string)
    end sub
    public overrides function tostring() as string
    return Value
    end sub
    end class

    ComboBox1.items.add(new cbItem("Key","Value")
    or also
    ListBox1.items.add(new cbItem("Key","Value")

    later, recover with:
    dim cb as cbItem=ctye( combobox1.selecteditem,cbItem)



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    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…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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

    11 Experts available now in Live!

    Get 1:1 Help Now