get all valuemembers in a combobox

Posted on 2008-11-17
Last Modified: 2012-06-22
I have a combobox of 31 items.  The datasource for the combobox is a datatable that has a displaymember and a valuemember.

How can I get the valuemember of each item in the combobox?
Question by:logoncom
    LVL 8

    Expert Comment

    foreach(ListItem item in combo1.Items)
       // access to item value with item.Value;
    LVL 6

    Expert Comment


    For xxx As Integer = 0 To ComboBox1.Items.Count - 1
    'where ComoboBox1 is your object name
    LVL 26

    Accepted Solution

    another method
    DataTable dt = (DataTable)comboBox1.DataSource;

    for(int i = 0; i < dt.Rows.Count; ++i)
        string displayText = dt.Rows[i][comboBox1.DisplayMember].ToString();
        string valueItem = dt.Rows[i][comboBox1.ValueMember].ToString();

    Author Closing Comment

    This works perfect... the other 2 posts here do not work.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now