DataBound ComboBox multiples

Megalith

Well-known member
Joined
Aug 21, 2006
Messages
66
Programming Experience
10+
hi can anyone help me with a problem i'm having, I have a ComboBox on a form which is bound to a city field in my database and sorted prior to display, my problem is that due to the nature of the field in question there are mutiple entries is it possible to remove these duplicates. so i end up with a list containing say "CA, ME, TX" rather than "CA, CA, CA, CA, ME, ME, TX, TX, TX,TX"

The combobox is bound using Datasource, data member and value member properties from the combobox properties and it is sorted using the
sort property on the binding source control.
 
Yikes so how would i do that? do i create a new datatable and add only unique rows (after sorting) at this column and use this for instance or is there another way? if i have to do it that way i might as well add them to the combobox without it being bound!
 
Last edited:
SELECT DISTINCT is used in SQL
 
If the combo box is editable, so freetext can be typed then your datasource for it would come from the SQL:

SELECT state FROM employees GROUP BY state



try to avoid DISTINCT even though it is logically identical to group by in this particular case - if you get into the habit of thinking "distinct is used to filter out duplicate rows" it can lead you to write some very inefficient queries throughout your SQL life - always endeavour to resolve duplication (introduced by [partial] cartesian joins) through more accurate join or where clause parameters.

If your combo is not freetext then some lookup table needs to exist with all the possible choices. If the list is small or will not change, then it is fine to code it into the exe itself
 
Back
Top