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

Add items in combo box

Status
Not open for further replies.

HRHK

Programmer
Jun 5, 2005
83
US
How can I add items in cb?
I used following code in the form load event, but
when I click the dropdown list, it shows blank items.
However, I can select the blank item. Then it shows
the text of the item. Strange, can somebody explain why it's doing this?
Thanks.

cb.Items.Add("LName")
cb.Add("FName")
 
How are you even getting this application to compile? In my IDE, the "cb.Add("FName")" line shows an error, because there is no Add method of the combobox class.

Try running this in your Form_Load as a test:

For r As Integer = 0 to 9
cb.Items.Add("Item_" & r.ToString())
Next

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
It should be cb.Items.Add("LName").

I tried above, it adds the item in the cb, but when I dropdown the cb, there's blank items. But when I select any blank item, it shows the text then.
 
Are you trying to add the literal value "LName", or a field from a database that is named LName?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Literal value "LName" and "FName
 
Then the cb.Items.Add() should work.

I suspect you may be seeing a paint problem -- are you running on a dual-monitor computer? That helps solve these problems tremendously because you can run the app on one screen, and have your source code up in the debugger on the other. Otherwise, whenever the debugger hits a breakpoint, it jumps to the front of the z-order, causing a repaint when control returns to your program. If you have code in an event which is in the paint call-chain, this will cause some problems for you. ;-)

A quick check to see if this is the problem -- clear all your breakpoints and just run it like a user would.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Ran it w/o breakpoints, same result.
The items are there, just seeing blank instead of "LName"/"FName". I changed the cb property dropdownstyle to dropdownlist, but it didn't help. HELP!
 
Is it possible your colors got changed on the control so that the forecolor matches the background color?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
chiph,

I thought of that too, but in that situation when you pass the mouse cursor over the items in the list, they are highlighted and the text is then visible.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top