adding a item and setting value to that item in  List Box in C#

Posted on 2007-08-08
Last Modified: 2013-12-17
Hi Expert ,
           I am developing win form app in C#. I have a list Box. By wrting code I am inserting Item to List Box
      int index = this.PartList.Items.Add("abc");
Now I want set Value to that Item say (5). I am from VC++ background. In VC++ 6 , it have that facility. Plaese tell me how to do that one.

Question by:suvendulaha
    LVL 96

    Expert Comment

    by:Bob Learned
    If you want a value, then you can do something like this:

    DictionaryEntry[] entryList = new DictionaryEntry[] { new DictionaryEntry("abc", "5)}

    this.PartList.DataSource = entryList;
    this.PartList.DisplayMember = "Key";
    this.PartList.ValueMember = "Value";

    LVL 8

    Accepted Solution

      ListBox list = new ListBox();
            ListItem item = new ListItem();
            item.Value = 5;
            item.Text = "a";
    LVL 22

    Expert Comment

    Instead of using the simple add, you can do this:
    ListItem item = new ListItem();
    item.Text = "abc";
    item.Value = 123;


    Author Comment

    It is giving error for ListItem in win form app .

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now