Inserting Unbound Items to a Bound Combo Box

wabs27

Member
Joined
Jul 31, 2006
Messages
11
Programming Experience
5-10
Hi,

I have a data bound combobox in my application. I would like to add some unbound items to the same combo box. For example, instead of the first record being selected, I would like to have an item "Select...". I would also like to add an "Add New" item to the combo box which would take the user to a form to insert a new record.

Does anyone know how to add an unbound item to the combo box? My combo box is currently being generated from a data set? I tried cmbCategory.items.insert(0,"Select...") but that gave me an error: Items collection cannot be modified when the DataSource property is set.

Any feedback would be greatly appreciated.

Thank you.
 
You can't do that, either bind or not bind. What you can do is to set the Text property of ComboBox after it's bound to display some text before selection is made. Once selection is made this text will dissappear. Your 'Add New' sounds as it belongs in a Button user interface.
 
I have done some research around here and learned that in such a case we can iterate through the dataset in a loop and add each record into the combo box instead of binding the data to the control.

I ran into a small problem with this though. The method I know of to add data to a combo box is:

ComboBox1.Items.Insert(index, item)
as in...
Combo1.Items.Insert(0, "Select...")

QUESTION: However, how can you add both a displaymember and a valuemember to a combobox this way?

And JohnH, this is hwo the AddNew feature will work. The onchange event for the combo box will check to see if the selecteditem is "Add New". If it is it will show the Add New form.
 
Back
Top