protected override void SavingVisit(DataGridContext sourceContext)
        {
            if (sourceContext.ParentDataGridContext == m_rootDataGridContext)
            {
                // Ensure to get a reference to the System.Data.DataRow when doing a
                // save/restore of a System.Data.DataRowView since the view is recreated
                // for every detail views
                object parentItem = ItemsSourceHelper.TryGetDataRowFromDataItem(sourceContext.ParentItem);

                m_itemsToExpand.Add(new WeakReference(parentItem));
            }
        }
        public WeakDataGridContextKey(DataGridContext dataGridContext)
        {
            DataGridContext parentDataGridContext = dataGridContext.ParentDataGridContext;
            int             level = 0;

            while (parentDataGridContext != null)
            {
                level++;
                parentDataGridContext = parentDataGridContext.ParentDataGridContext;
            }

            System.Diagnostics.Debug.Assert(((level == 0) || (dataGridContext.SourceDetailConfiguration != null)),
                                            "A child dataGridContext must have a SourceDetailConfiguration.");

            m_sourceDetailConfigurationRelationName = (dataGridContext.SourceDetailConfiguration != null) ?
                                                      dataGridContext.SourceDetailConfiguration.RelationName : string.Empty;

            if (level > 0)
            {
                // We are NOT dealing with the root DataGridContext.

                // Build the tree of master items.
                m_weakItemsTree = new WeakReference[level];

                DataGridContext tempDataGridContext = dataGridContext;
                for (int i = level - 1; i >= 0; i--)
                {
                    // Ensure to get a reference to the System.Data.DataRow when doing a
                    // save/restore of a System.Data.DataRowView since the view is recreated
                    // for every detail views
                    object parentItem = ItemsSourceHelper.TryGetDataRowFromDataItem(tempDataGridContext.ParentItem);

                    m_weakItemsTree[i] = new WeakReference(parentItem);

                    tempDataGridContext = tempDataGridContext.ParentDataGridContext;
                }
            }

            this.Initialize();
        }
        internal WeakDataGridContextKey(DataGridContext dataGridContext)
        {
            var parentDataGridContext = dataGridContext.ParentDataGridContext;
            var level = 0;

            while (parentDataGridContext != null)
            {
                level++;
                parentDataGridContext = parentDataGridContext.ParentDataGridContext;
            }

            Debug.Assert(((level == 0) || (dataGridContext.SourceDetailConfiguration != null)), "A child dataGridContext must have a SourceDetailConfiguration.");

            m_sourceDetailConfigurationRelationName = (dataGridContext.SourceDetailConfiguration != null) ? dataGridContext.SourceDetailConfiguration.RelationName : string.Empty;

            if (level > 0)
            {
                // We are NOT dealing with the root DataGridContext.

                // Build the tree of master items.
                m_weakItemsTree = new WeakReference[level];

                var tempDataGridContext = dataGridContext;
                for (int i = level - 1; i >= 0; i--)
                {
                    // Ensure to get a reference to the System.Data.DataRow when doing a
                    // save/restore of a System.Data.DataRowView since the view is recreated
                    // for every detail views
                    var parentItem = ItemsSourceHelper.TryGetDataRowFromDataItem(tempDataGridContext.ParentItem);

                    m_weakItemsTree[i] = new WeakReference(parentItem);

                    tempDataGridContext = tempDataGridContext.ParentDataGridContext;
                }
            }

            m_hashCode = WeakDataGridContextKey.CalculateHashCode(m_sourceDetailConfigurationRelationName, m_weakItemsTree);
        }