Solved

master & detial table with listview

Posted on 2004-03-28
13
186 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now