Board index » delphi » Adding items to a ComboBox

Adding items to a ComboBox

Can anyone out there help me with this problem?

I'm trying to populate a ComboBox in Delphi v1 with all possible contents of
a field.

The table being used contains about 1500 records with the field in question
containing any one of about 50 different values.

If I try to use a DBLookupCombo component, the combo is populated with every
occurrence of each data item - ~1500 items rather than just the 50 possible
choices I need.

Any ideas please

/\/\ark

 

Re:Adding items to a ComboBox


Quote
Mark Hunter wrote:

> Can anyone out there help me with this problem?

> I'm trying to populate a ComboBox in Delphi v1 with all possible contents of
> a field.

> The table being used contains about 1500 records with the field in question
> containing any one of about 50 different values.

> If I try to use a DBLookupCombo component, the combo is populated with every
> occurrence of each data item - ~1500 items rather than just the 50 possible
> choices I need.

> Any ideas please

> /\/\ark

Populate it with a TQuery with the SQL set to:

Select distinct field1 from Table1

It will select each value exactly once. It will be advisable to index
the table on the field.

HTH

Re:Adding items to a ComboBox


Probably the best thing to do would be to have a seperate table that you
allow the user to edit that just contains the unique list.

However, if you populate the combobox by hand (open the table and add the
values to the items property) you can protect against dupes like this....

  if combo.items.indexOf(sValue) = -1 then begin
    combo.items.add(sValue);
  end;

Quote
Mark Hunter wrote in message <6h2648$mo...@panther.rmplc.co.uk>...
>Can anyone out there help me with this problem?

>I'm trying to populate a ComboBox in Delphi v1 with all possible contents
of
>a field.

>The table being used contains about 1500 records with the field in question
>containing any one of about 50 different values.

>If I try to use a DBLookupCombo component, the combo is populated with
every
>occurrence of each data item - ~1500 items rather than just the 50 possible
>choices I need.

>Any ideas please

>/\/\ark

Re:Adding items to a ComboBox


Maybe you can try TQuery component with datasource.

Raimonds.

Quote
> occurrence of each data item - ~1500 items rather than just the 50 possible

Other Threads