?
Solved

get all valuemembers in a combobox

Posted on 2008-11-17
4
Medium Priority
?
794 Views
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?
0
Comment
Question by:logoncom
4 Comments
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22980632
foreach(ListItem item in combo1.Items)
{
   // access to item value with item.Value;
}
0
 
LVL 6

Expert Comment

by:carlsiy
ID: 22980996

For xxx As Integer = 0 To ComboBox1.Items.Count - 1
     MessageBox.Show(ComboBox1.Items(xxx).ToString())
Next
'where ComoboBox1 is your object name
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 22981229
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();
}
0
 

Author Closing Comment

by:logoncom
ID: 31517675
This works perfect... the other 2 posts here do not work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…

621 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