Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - How to change parent of child records?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to change parent of child records?

 Post Reply Post Reply
Author
Message
kylechen View Drop Down
Groupie
Groupie


Joined: 29 November 2004
Status: Offline
Points: 57
Post Options Post Options   Thanks (0) Thanks(0)   Quote kylechen Quote  Post ReplyReply Direct Link To This Post Topic: How to change parent of child records?
    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.
 
Back to Top
kylechen View Drop Down
Groupie
Groupie


Joined: 29 November 2004
Status: Offline
Points: 57
Post Options Post Options   Thanks (0) Thanks(0)   Quote kylechen Quote  Post ReplyReply Direct Link To This Post 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


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.