Getting Parent Record for child record in master detail relationship

Hi,

I have created master-detail relationship in the grid grouping control to show the child level data below the parent record. I want to get the parent record for the specific child record i have. I tried the record.parentrecord or Record.parent but not able to get the parent record for the child record.
Please give me some pointer .

Thanks
Harshad


4 Replies

HA Harshad December 12, 2007 12:41 PM UTC

I have tried ParentRecord.GetRelatedRecords(RelationDescriptor) but this is giving me null value.



AD Administrator Syncfusion Team December 12, 2007 12:46 PM UTC

Given a child record, childRecord, try code like:

GridRecord parentRecord = childRecord.ParentChildTable.ParentDisplayElement.GetRecord() as GridRecord;




AD Administrator Syncfusion Team December 12, 2007 12:59 PM UTC

The above code assumes you have a single GridGroupingControl and are showing the master-details as expandable records in this single grid.



AD Administrator Syncfusion Team December 12, 2007 01:09 PM UTC

If you are using 2 grids to display the Master-Details, then getting the parent record is straight-forward if the childrecord is being displayed in the child grid. You could just get the CurrentRecord from teh parent grid. Here is code in the child grid's doubleclick event to illustrate this.

void parentToChildGrid_TableControlCellDoubleClick(object sender, GridTableControlCellClickEventArgs e)
{
if (parentTableGrid.Table.CurrentRecord != null)
{
this.Text = parentTableGrid.Table.CurrentRecord.ToString();
}
}


But if you just want to locate the parent record for an abitrary child record whether or not it is being displayed, then I am not sure there is a simple way to do this. One way you could find it is to look through the parentTableGrid.Table.UnsortedRecords collection and just look for the particular field value that would match a parent record to the related childrecord.


Loader.
Up arrow icon