Add "Please Select" in DataBound ComboBox


I have a databound combobox which bound to a datatable. I want to put the initial value in my combobox, such as "Please Select Item". However, I've tried setting the Text property and also try to insert a new row without any luck. It seems after the combobox bounded to a datatable, its items can't be changed anyway.

Could someone help me with some tips?

Thanks in advance

Who is Participating?
i thinkg that you will have to add the "Please select item" in the datatable before bind it, like this

DataRow dr = dataTableObject.NewRow();
dr[index of the valuemember] = 0;
dr[index of the displaymember] = 'Please Select Item';
dataTableObject.Rows.InserAt(dr, 0)

MiBlgAuthor Commented:
Hi mmarinov,

Sorry for the late reply.

 I've followed your suggestion but, it's failed when the combox has to be intialized to a value, for example, the 3rd item should be selected.

Your suggestion works perfectly only if the 1st item selected.

Any more ideas?

what do you mean by the "initialized" this is a common method of inserting data in a datatable
there didn't mension about combobox
when you have the filled datatable object how do you bind the combox to it ?

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

MiBlgAuthor Commented:
I mean the scenario is like this:

I've populated the combobox using your way:

DataRow dr = MyDataTableNewRow();
dr["Value"] = 0;
dr["Text"] = 'Please Select Item';
MyDataTable.Rows.InserAt(dr, 0)
myCombo.DataSource = myDataTable
myCombo.ValueMember = "Value"
myCombo.DisplayMember = "Text"

When The Form is in Add Mode, the selected item in the combo box is "Please Select Item" (1st item). This works fine.

However, when the Form is in Editing, I have to make myCombo show the value based on the database. For example:

mycombo.SelectedValue = "blabla"

It throws an error when doing this, but when there's no "Please select" it works fine. (I remove the code to insert new row)

What's wrong here?
what error do you receive ?

MiBlgAuthor Commented:
I Initialize the dr["Value"] to int32.MaxValue, then the error is Index out of range.
MiBlgAuthor Commented:
I still don't know how to figure this out, but anyway you have already pointed me out the way. Thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.