Combo Box General Question

QuestionTime

New member
Joined
Jul 29, 2006
Messages
4
Programming Experience
Beginner
Hello:

I am actually stuck with a combo box question. I've been successfully load the data to the dataset and fill it into my combo box. However, when I was trying to add a new combo item after the combo box had been filled, it did not let me to do it.

Dataset contain just Users Name and User ID (User Name had been set to display member, User ID had been set to value member). Its all load to to the combo box which is fine. I was planning to add " === All === " in the index 0 of my combo box. It won't let me do it due to datasource had been set. I did try to insert this "=== All === " before setting datasource, however, once datasource had been set, it will wipe out everything in my combo box. Tired to use the combo insert method - failed as well.

Anyone have idea how to fix this problem ? Is that mean everytime you loading data onto combo box, you are not allow to add new item ?

Thank you.

Question Time.
 
Thats exactly what it means i'm afraid. You can't modify a bound combo's item collection, if you think about it, to do so would mean that you would violate the 'contract' that batadinding enforces.
 
Thankx for your reply.
I am thinking to loop through the data table inside my dataset onto the combo box. But it sounds totally not logical and wasting the idea for data bound.
 
But that's the whole point of databound.... it makes perfect sense that you can't simply add to it if it's databound. There are a number of solutions:
1) Add the item you want, then loop through the DT and add through code.
2) Add the item you want, then loop through using a DataReader to add through code
3) Create an array list, add the item you want, loop through the DT/DR add items to the arraylist, then bind the array list to the combobox
4) Include the item you want in the select statement in the first place. Huh? What? Been there a dozen times, but if you include a "SELECT '=== All === '" then UNION ALL that to your original select statement (take care, as the number of fields in both sections of queries MUST MATCH) then you can bind all you wnt with it.

-tg
 
Back
Top