Initial value in a combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to add an initial value into a databound combo box on a
windows form.
I have a combo box set to dropdown list so users cannot add their own items
and I fill the data from a dataset in the following code

DataSet dsTitles = DataAccess.GetLookupItems("Titles", "Title");
cbPersonTitle.DisplayMember = "Title";
cbPersonTitle.ValueMember = "TitleID";
cbPersonTitle.DataSource = dsTitles.Tables["Titles"];

However I want the initial value to be "Please select....." and not an item
from the database.
 
ListItem LI = new ListItem("PLease Select...", "-1");
LI.Selected = true;
cmbo.ListItems.Add(new ListItem(LI);
// Then add the other items from your dataset...
foreach (DataRow dr in dsTitles["Titles"])
{
string sTitle = dr["Title"].ToString();
string sTitleID = dr["TitleID"].ToString();
cmbo.ListItems.Add(new ListItem(sTitle, sTitleID );
}
 
Back
Top