Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

master & detial table with listview

Posted on 2004-03-28
13
Medium Priority
?
196 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

618 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