[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

master & detial table with listview

Dear Experts

I got a master and detail tables and i have two questions :

1. These two tables are linked together by field named number. Is there a proper way so when i insert a new record in the master table so it will effect in the detail one and it will insert a new record with the same title as the master's one.

2. How can i fill both tables in the listview so i can show the master and the detail fields related to it

thanks a lot

0
ibrobar
Asked:
ibrobar
  • 6
  • 4
1 Solution
 
shaneholmesCommented:
Ok, if you have the following scenario,

MasterTable
----------------
Id (AutoInc)
Field1
Field2

ChildTable
-----------
Id (AutoInc)
MasterId (Number)
Field1
Field2

Make sure you have a TDataSource with its DataSet property set to your Master Table


you will need to set the Child Table's MasterSource property to the
Master Table's datasource (you should have a TDatasource connected to your master table - right?)

Then you need to set the Child Tables MasterField property to the Joined fields of Master Table's ID and Child Table's MasterId

When you click the MasterFelds property, you will get a dialog box where you can join these two fields.

Let me know if you need anymore help!

Shane
0
 
ibrobarAuthor Commented:
Dear Shane

thanks a lot but I know all of this , actually i did the link between the master and detail tables but my question is :

when i insert a new record in the master table. let us say that the value of the field that connecting between the two table number=10.
my question is :number field in the detail table it will be automatically 10 or i have to insert it

thanks

what about the other question

How can i fill both tables in the listview so i can show the master and the detail fields related to it
thanks
0
 
shaneholmesCommented:
Yes the number field in the detail table will automatically be 10

You cant fill both tables in a listview (if your using the standard delphi listview from the Win32 tab).

You will need a third party or decendent component which will give you two levels.

 
 There are some freeware, shareware, and commercial ones available, let me see if i can find you one!

Shane
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ibrobarAuthor Commented:
thanks shane
but it's not added automatically in the detail field i don't know why

0
 
shaneholmesCommented:
You could use two TListView's

One for master & one for child

You would popluate the master as such (of the top of my head)

var
 Item: TListItem;

tblmaster.First
while not tblmaster.EOF do
begin
 Item:= lvwMaster.Items.Add;
 Item.Caption:= tblMaster.FieldByName('Id').asString;
 Item.SubItems.Add(tblMaster.FieldByName('Field1').asString);
 Item.SubItems.Add(tblMaster.FieldByName('Field2').asString);
 tblmaster.Next
end;


Now when a user clicks on a master record in the listview, you would
iterate the child table and fill the child listview with those records corresponding to the master table

var
 Item: TListItem;

tblChild.First
while not tblChild.EOF do
begin
 if  tblChild.FieldByName('MasterId').asString = lvwMaster.Items[lvwMaster.ItemIndex].caption then
 begin
  Item:= lvwChild.Items.Add;
  Item.Caption:= tblChild.FieldByName('Id').asString;
  Item.SubItems.Add(tblChild.FieldByName('MasterId').asString);
  Item.SubItems.Add(tblChild.FieldByName('Field1').asString);
  Item.SubItems.Add(tblChild.FieldByName('Field2').asString);
 end;
 tblChild.Next
end;

SHane
0
 
shaneholmesCommented:
what are you using for a database?

Shane
0
 
ibrobarAuthor Commented:
i am using paradox what you think
what is your full name by the way
0
 
shaneholmesCommented:
What i think?

How would I know, there are 100's of databases you could be using.....

My full name is Shane Holmes!

Are you using the standard BDE components?

TDatabase, TTable, TDataSource, etc.

Shane

0
 
ibrobarAuthor Commented:
yes i am using standard components
i appreciate your help thanks

0
 
shaneholmesCommented:
is it small enough to zip up and email to me so i can look , cause if you followed the steps i layed out up above, it should work just fine

Shane (holmesshane AT charter DOT net)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now