Print Page | Close Window

How to change parent of child records?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=9057
Printed Date: 14 November 2025 at 5:50am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to change parent of child records?
Posted By: kylechen
Subject: How to change parent of child records?
Date Posted: 10 December 2007 at 3:52am
Hi there,
 
I'm using CXTPReportControl with one column displayed as a tree style. I need to change the child records' parent dynamically. My logic is:
 
CXTPReportRecord *pItem ;    // the child item to move to new parent
CXTPReportRecord *pOldParent = pItem->GetRecords()->GetOwnerRecord() ;
CXTPReportRecord *pNewParent ;  // the target record to hold the child
 
pOldParent->RemoveRecord(pItem) ;
pNewParent->Add(pItem) ;
 
However, when I call pOldParent->RemoveRecord(pItem), the pItem would be released by "InternalRelease" internally in CXTPReportControl~~~
 
Is there any easy way for this? Anyone can help will be much appreciated.
 



Replies:
Posted By: kylechen
Date Posted: 11 December 2007 at 8:04pm
The solution is from Codejock support:- (For anyone has the same problem)
 
Can try using TreeAddRef() method before removing an item from an old parent.

For example, the following work in our sample for me:

void CTreeViewDlg::OnOK()
{
CXTPReportRecord *pOldParent = m_wndReport.GetRecords()->GetAt(2);
CXTPReportRecord *pItem = pOldParent->GetChilds()->GetAt(0) ; // the child item to move to new parent
CXTPReportRecord *pNewParent = m_wndReport.GetRecords()->GetAt(0); // the target record to hold the child

pItem->TreeAddRef();
pOldParent->GetChilds()->RemoveRecord(pItem);
pNewParent->GetChilds()->Add(pItem);

m_wndReport.Populate();
//CDialog::OnOK();
}

Should be "InternalAddRef", there's no "TreeAddRef" in XTP 11.2.0





Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net