Solved

master & detial table with listview

Posted on 2004-03-28
13
188 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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