The Dink Network

Databinding in Visual Studio

January 18th 2012, 04:07 AM
dinkdead.gif
Before I go and sign up in some other forum to ask my silly questions, I wonder if there are any .NET programmers lurking around here that can help me?

Does anyone know how I can set a default value on a databound combobox? For example, I've bound a combobox to a database with a list of book authors and want the box to say "Select author..." when the form is first loaded.

The closest I can get is to do
comboAuthors.SelectedIndex = -1

and get a blank entry as default. Can't manage to get any text in there though.
January 18th 2012, 10:31 AM
duck.gif
I'm not a .NET programmer, but does this help?
January 18th 2012, 12:02 PM
dinkdead.gif
Nope. Tried googling around but can't find a solution that works.
January 18th 2012, 07:03 PM
custom_marpro.png
Marpro
Peasant He/Him bloop
 
Hey.

You'll need to insert a "default" value to your item list. Something like this:

comboAuthors.Items.Insert(0, new ListItem("Select author...",""));
comboAuthors.Items[0].Selected = true;
January 19th 2012, 03:59 AM
dinkdead.gif
Tried that

'VB:
comboAuthor.Items.Insert(0, "Select author...")
comboAuthor.SelectedIndex = 0
Does nothing.

Odd. SelectedIndex = -1 gives a blank default, but if I do
comboAuthor.Items.Insert(0, "Select author...")
comboAuthor.SelectedIndex = -1
then there's no blank, just the 1st name in the database.

And if I try inserting before the
Me.TbAuthorsTableAdapter.Fill(Me.BooksDataSet.tbAuthors)
line instead of after, then I end up with an empty combobox.