[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

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.
0
SRP
Asked:
SRP
  • 3
  • 3
  • 3
  • +3
1 Solution
 
SRPAuthor Commented:
Edited text of question.
0
 
SRPAuthor Commented:
Edited text of question.
0
 
kretzschmarCommented:
? 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 ?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
simonetCommented:
something like the code above works great for me:

with Table1, ComboBox1.items do
try
   beginupdate;
   disablecontrols;
   clear;
   first;
   while not eof do
   begin
     add(fieldbyname('showname').asstring);
     next;
   end;
finally
   enablecontrols;
   endupdate;
end;

This works for me, and I guess it's what you're looking for.

Yours,

Alex

yours,

Alex
0
 
men xinCEOCommented:
Easy.

menxin
0
 
kretzschmarCommented:
aah, checked, well done alex
0
 
she3i3iCommented:
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.  
0
 
she3i3iCommented:
of course... clearing the comcobox before each time you are going to do this... is obvious... as you can see in Alex's code :)
0
 
kretzschmarCommented:
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 ;-)
0
 
AlphomegaCommented:
Why don't use a TDBLookupComboBox with ListSource on your Table and listfield on ShowName ?????
It's easier ...
0
 
simonetCommented:
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
0
 
simonetCommented:
SRP, are you there?
0
 
SRPAuthor Commented:
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
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 3
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now