Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox - Loop Through Displayed Values

Status
Not open for further replies.

eb24

Programmer
Dec 17, 2003
240
US
I am trying to loop through the values of a ComboBox and it seems that when I use the following:
Code:
foreach (object item in this.Items)
it loops through the whole collection from the pertinent Business Object. I would only like to loop through the values given in the DisplayMember, e.g. ItemCode.

Any advice will be greatly appreciated.
 
Cast the current item object at index i to the Business Object
and then you can access the ItemCode property for that Business Object.


Code:
for(int i = 0; i < this.comboBox.Items.Count; i++)
{
MessageBox.Show(((Business)(this.comboBox.Items[i])).ItemCode.ToString());
}

Thanks.

gpp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top