In cases where I am binding to a data source, I insert a dummy, blank
item in the beginning of the data source.
--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:
http://bphillips76.spaces.live.com
"RobinS" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed):
> You can't if the combobox is databound. Try setting the SelectedIndex
> to -1 instead.
>
> Robin S.
> --------------------------------------
> "Matt" <(E-Mail Removed)> wrote in message
> news:78CBD3F6-4BEB-457E-8864-(E-Mail Removed)...
> > How do you add a blank to the top of a comboBox in a Windows Form?
> > I've done
> > this with drop down lists in web forms but the ListItem that I used
> > there
> > doesn't appear to exist in a win form. I'm loading the ddlCategory
> > comboBox
> > with an ID(int) for value and Category(string) for Display out of a
> > SQL DB
> > using a SP. Once these values are loaded I want to add a blank to the
> > top of
> > the list and have it be selected initially. What I've tried gives me
> > an
> > error of "Items collection cannot be modified when the DataSource
> > property is
> > set."
> >
> > private void LoadCategory()
> > {
> > // Load the Source DDL
> > ExpenseSpreadSheet.ExpenseClass.ExpenseClass getCategory =
> > new
> > ExpenseSpreadSheet.ExpenseClass.ExpenseClass();
> >
> > System.Data.DataSet ds;
> > ds = getCategory.GetCategory();
> > DataTable dt = ds.Tables[0];
> >
> > ddlCategory.DataSource = ds.Tables[0];
> > ddlCategory.DisplayMember = "Category";
> > ddlCategory.ValueMember = "id";
> >
> > // I have been trying to do this to add the blank.
> > ddlCategory.Items.Add(" ");
> > }
> >
> > Thanks,
> > Matt