Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2007-08-08
Medium Priority
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
ID: 19656028
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";


Accepted Solution

sabeesh earned 1500 total points
ID: 19656047
  ListBox list = new ListBox();
        ListItem item = new ListItem();
        item.Value = 5;
        item.Text = "a";
LVL 22

Expert Comment

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


Author Comment

ID: 19656627
It is giving error for ListItem in win form app .

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 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