views:

188

answers:

5

I want to populate the contents of a combobox with country names/flags reading from a database table. I want the first item to represent no selection. (The user may not know the country info during first insert) Should I include an item for this in db. Or should I add an item representing the no-select to the array in the code. Which approach is more "pro" coding.

A: 

I would not list anything in the database if I were doing this, and I would definitely not include a null value in the database to represent no choice. If you would like to have a no choice entry, I would include something like, "not selected" in the database.

Irwin M. Fletcher
+1  A: 

I usually handle this case with a union statement, rather than put the table

create view CountryComboView
as
select 0 as Code,'None selected' as name
union
select CountryCode,CountryName from CountryTable

I agree with Irwin, not to put the None Selected in the database...

Sparky
A: 

No you don't. A combobox is not usable with 250 entries. You might want to use a pop-up listbox, or perhaps a auto-completing field.

Stephan Eggermont
A: 

No selection is more something that should fit in the view.
Typically most GUI components allow you to add a "no selection" entry at run time. This also allows you to localize your entry.

borisCallens
A: 

You could make it easy and make the first item in the table the "Not Selected" item that cannot be modified or deleted (it is always there). After that, all your countries are listed in alphabetical order. The countries would have to be sorted prior to inserting into your database so you don't disrupt your "Not Selected" at index 0 scenario. You then bind this table to your combobox. Don't sort your ComboBox either.

0A0D