We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Getting Parent Record for child record in master detail relationship

Thread ID:

Created:

Updated:

Platform:

Replies:

70469 Dec 12,2007 11:56 AM UTC Dec 12,2007 01:09 PM UTC Windows Forms 4
loading
Tags: GridControl
Harshad
Asked On December 12, 2007 11:56 AM UTC

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


Harshad
Replied On December 12, 2007 12:41 PM UTC

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


Administrator [Syncfusion]
Replied On December 12, 2007 12:46 PM UTC

Given a child record, childRecord, try code like:

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



Administrator [Syncfusion]
Replied On 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.


Administrator [Syncfusion]
Replied On 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.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;