Master-detail relationship

Master-detail relationship

Post by Guille » Sat, 29 Nov 2003 21:12:43


Hello,

I've got following problem. I need a DBGrid to display the values of an
ADODataset depending on the value of a DBCombobox (sort of master-detail
relationship). The problem is I need to do this at run-time, so I should set
MasterSource, MasterFields and DetailFields properties. Well, MasterSource
and MasterFields are not a problem at all but, where can I set DetailFields
property? I haven't found it anywhere.

As an alternative I thought about using filters, but I don't think this is
such a good idea. However I tried it but always have an OleException raised
telling me something like "type not appropiate". An example of the filter I
tried to set was something like:

ADODataset.Filter := ' MyField = ' + FilterCondition;
ADODataset.Filtered := true;

where FilterCondition would be the actual Text value from the combobox.

Can anyone help me please? Thanks!

Guillem
 
 
 

Master-detail relationship

Post by Guille » Mon, 01 Dec 2003 00:27:15

Ok, I did as you suggested. DBLookUpComboBox is filled properly, but
something's wrong with the detail dataset. Somehow the DBGrid linked to it
does not show anything (and I know there is data inside), and if you try to
insert new values when you exit the last field all values disappear and
first cell is focused and assigned the value of the DBLookUpComboBox. I
suppose the problem is that i've not assigned the field to be joined with
the DBLookUpComboBox value. But how do I this?

I'll post here the values of the properties I'm using

MasterDataSource.DataSet := MasterADODataset; //for the DBLookUpCombobox
DetailDataSource.DataSet := DetailADODataset; //for the DBGrid
DetailADODataset.MasterSource := MasterDataSource;
DetailADODataset.MasterFields := 'id_company'; //field example
DBLookUpComboBox.DataSource := nil;
DBLookUpComboBox.ListSource := MasterDataSource;
DBLookUpComboBox.KeyField := 'id_company';
DBGrid.DataSource := DetailDataSource;

Hope you can help me. Thanks for all!
Guillem

"Brian Bushay TeamB" < XXXX@XXXXX.COM > escribien el mensaje
>> Since Detailfields does not exist you won't find it. >> >> >> >> To use a DBLookupComboBox as a Master source >> In Object Inspector, leave datasource and datafield blank. Set >> ListSource to the table that has the field values you want displayed and >> set Keyfield Field to that field. >> >> Getting the dblookupcombobox to display the first record on startup is a >> bit trickier. In my Form.Show event handler/method, do this: >> PostMessage(DBLookupComboBox1.handle,WM_CHAR,ord('A'),0); >> If you don't post a wmchar message, the lookupcombobox is empty when the >> program starts up. >> >> -- >> Brian Bushay (TeamB) >> XXXX@XXXXX.COM

 
 
 

Master-detail relationship

Post by Guille » Tue, 02 Dec 2003 19:46:07

Ok, but anyway, how do you tell the dataset which fields are to be joined
with the masterFields?

Thanks for your help :)

"Brian Bushay TeamB" < XXXX@XXXXX.COM > escribien el mensaje
>>>>I'll post here the values of the properties I'm using >>>> >>>>MasterDataSource.DataSet := MasterADODataset; //for the DBLookUpCombobox >>>>DetailDataSource.DataSet := DetailADODataset; //for the DBGrid >>>>DetailADODataset.MasterSource := MasterDataSource; >>>>DetailADODataset.MasterFields := 'id_company'; //field example >>>>DBLookUpComboBox.DataSource := nil; >>>>DBLookUpComboBox.ListSource := MasterDataSource; >>>>DBLookUpComboBox.KeyField := 'id_company'; >>>>DBGrid.DataSource := DetailDataSource; >> >> That looks like it should work except that TadoDataset does not have a >> MasterSource property what it has is a Datasource property where it
inherits the >> values for masterfields >> -- >> Brian Bushay (TeamB) >> XXXX@XXXXX.COM
 
 
 

Master-detail relationship

Post by Guille » Fri, 05 Dec 2003 18:40:28

Thanks for your help Brian!

"Brian Bushay TeamB" < XXXX@XXXXX.COM > escribien el mensaje
>> >>>>Ok, but anyway, how do you tell the dataset which fields are to be joined >>>>with the masterFields? >> Yes you use Masterfields property or you can put a parameters in your
detail >> query that correspond to fields in your masterdataset. When the
parameter and >> fieldnames are the same the parameter value comes from the Dataset that
the >> Datasource property points to >> -- >> Brian Bushay (TeamB) >> XXXX@XXXXX.COM