private void OnNestedParentChange(DataRow child, XmlBoundElement childElement, DataColumn childCol)
{
Debug.Assert(child.Element == childElement && childElement.Row == child);
// This function is (and s/b) called as a result of ROM changes, therefore XML changes done here should not be sync-ed to ROM
Debug.Assert(_ignoreXmlEvents == true);
#if DEBUG
// In order to check that this move does not change the connected/disconnected state of the node
bool fChildElementConnected = IsConnected(childElement);
#endif
DataRow parentRowInTree;
if (childElement == DocumentElement || childElement.ParentNode == null)
parentRowInTree = null;
else
parentRowInTree = GetRowFromElement((XmlElement)childElement.ParentNode);
DataRow parentRowInRelation = GetNestedParent(child);
if (parentRowInTree != parentRowInRelation)
{
if (parentRowInRelation != null)
{
XmlElement newParent = GetElementFromRow(parentRowInRelation);
newParent.AppendChild(childElement);
}
else
{
// no parent? Maybe the parentRow is during changing or childCol is the ID is set to null ( detached from the parent row ).
DataRelation relation = GetNestedParentRelation(child);
if (childCol == null || relation == null || Convert.IsDBNull(child[childCol]))
{
EnsureNonRowDocumentElement().AppendChild(childElement);
}
else
{
DataColumn colInParent = FindAssociatedParentColumn(relation, childCol);
Debug.Assert(colInParent != null);
object comparedValue = colInParent.ConvertValue(child[childCol]);
if (parentRowInTree._tempRecord != -1 && colInParent.CompareValueTo(parentRowInTree._tempRecord, comparedValue) != 0)
{
EnsureNonRowDocumentElement().AppendChild(childElement);
}
//else do nothing because its original parentRowInRelation will be changed so that this row will still be its child
}
}
}
#if DEBUG
// We should not have changed the connected/disconnected state of the node (since the row state did not change) -- IOW if the original childElem was in dis-connected
// state and corresponded to a detached/deleted row, by adding it to the main tree we become inconsistent (since we have now a deleted/detached row in the main tree)
// Same goes when we remove a node from connected tree to make it a child of a row-node corresponding to a non-live row.
Debug.Assert(fChildElementConnected == IsConnected(childElement));
Debug.Assert(IsRowLive(child) ? IsConnected(childElement) : !IsConnected(childElement));
#endif
}