Link to home
Start Free TrialLog in
Avatar of SRP
SRP

asked on

table fields in combo box

I have a (paradox) table and one of the fields is show name, how do I create a combo box that shows all the records under that field name?

i.e. field is ShowName, the combo box shows: Starlight Express  Evita, Grease, Cats etc.
Avatar of SRP
SRP

ASKER

Edited text of question.
Avatar of SRP

ASKER

Edited text of question.
Avatar of kretzschmar
? what is your need for this
will you select,change one field of your currentrecord of your table with all available entries of this field based by the same table ?
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Easy.

menxin
aah, checked, well done alex
Hi again Alex :)

   Your code would give you multiple entries in your combobox if you have the same entry for the field showname in two or more records.

   SRP, here is what I do...

var
   S: String
begin
   with Table1 do
         First;
         while not EOF do begin
                 S := FieldByName('ShowName').AsString;
                 if S <> ComboBox1.Items then ComboBox1.Items.Add(S);
                 Next;
         end;
end;

   That's off the top of my head cause my code is all at home...

Cheers, Chris.  
of course... clearing the comcobox before each time you are going to do this... is obvious... as you can see in Alex's code :)
hi she3i3i,

i guess you mean this

if ComboBox1.Items.IndexOf(s) < 0 then ComboBox1.Items.Add(s);

instead of this
if S <> ComboBox1.Items then ComboBox1.Items.Add(s);

because you can't compare a string with a stringlist.

meikl ;-)
Why don't use a TDBLookupComboBox with ListSource on your Table and listfield on ShowName ?????
It's easier ...
Chris,

I supposed SRP's table have no repeated entries for the "ShowName" column. If it does, then an yet better solution prevent having repeated records would be to use a Query. By doing so we wouldn't have to use IndexOf, which can really slow down the whole thing in there are too many records.

So, if *and only if* there are repeated records (for the ShowName field) in the table, then this is an even better solution:

with Query1, ComboBox1.items do
try
   beginupdate;
   disablecontrols;
   clear;
   if active then close;
   if prepared then unprepare;
   SQL.Text := 'SELECT DISTINCT SHOWNAME FROM ALBUMTABLE';
   prepare;
   open;
   first;
   while not eof do
   begin
     add(fieldbyname('showname').asstring);
     next;
   end;
finally
   close;  
   unprepare;
   enablecontrols;
   endupdate;
end;

Yours,

Alex
SRP, are you there?
Avatar of SRP

ASKER

Sorry for not responding to all the great answers i have been away.

simonet
this answer works well for what I need to do. I also want to do a similar thing with a combobox that shows all possible fields for a given table. is this possible in the same kind of way?

thanks to simonet

SRP