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

Combo box

Status
Not open for further replies.

spylock

Programmer
Jun 16, 2003
1
US
I am display states in a combo box on a search form. I’m using an infoset that returns all states and I’m binding that to the combo box. The user doesn’t need to select a state if they don’t want to so I’m trying to figure out a way to add a blank line (display nothing) as the first item in the combo box. When the form is loaded the first state AB is displayed and I would like to have nothing displayed. Is there a way to add another display member that doesn’t display anything or just not display any values until the user selects the combobox?
 
The only way that I've found to do this is to use a DataReader object:

ListItem li = new ListItem ( "", "" );
cbBox.Items.Add ( li );

while ( dataReader.Read() )
{
li = new ListItem ( dataReader.GetString ( 0 ), dataReader.GetString ( 0 ) );
cbBox.Items.Add ( li );
}

...Or something along those lines. It adds the blank line before it goes into the datareader loop.

Problem is, when you actually bind the datareader or dataset to the combobox, it clears it first and then binds - So even if you added a blank line first, it would overwrite it.


-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top