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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify Index for Combo Box Items 1

Status
Not open for further replies.

kvang

Programmer
Oct 7, 2005
129
US
I am trying to specify the index of an item that I want to add to a combo box. This is the line of code I am using:

cboName.Items.Add(New ItemData(Name, NameIndex))

The output is:

ListViewItem: {Bob}
ListViewItem: {Sherry}

How do I display just the text of Name?

Example:

Bob
Sherry
 
It is propably my misunderstanding here, but could you say it again?
 
doesnt the combobox have an insertat method? then u can inseart at the required index

you should be able to get the text from the combobox.items[index].value(or text depends on how you added it) the text :)
 
I figured out how to display just the text. But now want to do something else. I'm populating a combo box with Employee Names from a table in a database. Each Employee Name has a unique ID in the table. I want to assign the ID as the index for each Employee Name. The starting ID may not start at 0 or 1. Any suggestions?
 
If u want to use only comboBox...then try the following. I am using dbDataReader for accessing my data.

Code:
cboName.Items.Add(DataReader("Name") & "  " & DataReader("NameIndex"))

 
I just want to display the Name and store the Index for later use, but hide the Index from the user.
 
Here's an option:

Populate a datatable and add the datatable to a dataview.

Use the dataview as the datasource for the combo box and sort the dataview using index field, set the display member to the name field.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top