Solved

master & detial table with listview

Posted on 2004-03-28
13
194 Views
Last Modified: 2010-04-05
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
Comment
Question by:ibrobar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
13 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10698400
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
 

Author Comment

by:ibrobar
ID: 10698435
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10698452
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
Technology Partners: 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!

 

Author Comment

by:ibrobar
ID: 10698465
thanks shane
but it's not added automatically in the detail field i don't know why

0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 125 total points
ID: 10698478
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10698483
what are you using for a database?

Shane
0
 

Author Comment

by:ibrobar
ID: 10698496
i am using paradox what you think
what is your full name by the way
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10698509
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
 

Author Comment

by:ibrobar
ID: 10698538
yes i am using standard components
i appreciate your help thanks

0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10698541
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question