Board index » delphi » Creting new List Boxes for each entry in the first List Box

Creting new List Boxes for each entry in the first List Box

Hi,

I have two fields in my database: Clusters and Counties.  For each
cluster, there are N number of counties.  I can create a list box for
clusters using Dblistbox.  When users highlight any cluster in the
cluster list box, I need to display a list box of counties in that
cluster only, so that they can select their county.  The selected county
should be assigned to the county field of the record.  How to do this in
Delphi.  I am new to Delphi.
(First time I am using Borland Newsgroup. Is there any way to post
questions from Newsgroup site.  I couldn't find "Post" icon.)
Thanks.

Shobha

 

Re:Creting new List Boxes for each entry in the first List Box


Quote
"Shobha Choudhari" <choudh...@scsu.edu> wrote in message

news:3B6830F3.25A2532E@scsu.edu...

Quote
> Hi,

> I have two fields in my database: Clusters and Counties.  For each
> cluster, there are N number of counties.  I can create a list box for
> clusters using Dblistbox.  When users highlight any cluster in the
> cluster list box, I need to display a list box of counties in that
> cluster only, so that they can select their county.  The selected county
> should be assigned to the county field of the record.  How to do this in
> Delphi.  I am new to Delphi.
> (First time I am using Borland Newsgroup. Is there any way to post
> questions from Newsgroup site.  I couldn't find "Post" icon.)
> Thanks.

Well, there are several ways to accomplish this. One would be to use a
lookup table that is filtered based on the selection in the first list box.
Since you are using a TDBListBox, you could set the MasterSource,
MasterFields property of the Countries lookup table to correspond to the
Clusters field of the main table. That way, it should only show you the
Countries which belong to the selected Cluster. Some things depend on the
type of database you are using and the way you have the tables set up.

Woody

Re:Creting new List Boxes for each entry in the first List Box


When you ask database related questions it helps if you tell us what
database you are using. Assuming you are using Paradox tables, any easier
method would be to use a DBGrid connected to the table that contains county
information and call TTable.SetRange to just display the counties for the
selected cluster.

If you want to use a list box you could ust a TListBox and load the counties
manually using code similar to the following.

with CountyTbl do
begin
  SetRange([SelectedCluster], [SelectedCluster]);
  CountyListBox.Items.Clear;
  while not EOF do
  begin
    CountyListBox.Items.Add(FieldByName('County').AsString);
    Next;
  end;
end;
--
Bill
(TeamB cannot answer questions received via email)

Other Threads