private void SetIndexes(int fromItemIndex, int startIndex)
 {
     for (int i = fromItemIndex; i < Count; i++)
     {
         IChildItemInternal <OwnerType> item = this[i] as IChildItemInternal <OwnerType>;
         item.SetIndexInParent(startIndex);
         startIndex++;
     }
 }
        protected override void RemoveItem(int index)
        {
            bool isCancel;

            base.BeginRemoveItem(index, out isCancel);
            if (isCancel)
            {
                return;
            }

            IChildItemInternal <OwnerType> childItem = this[index] as IChildItemInternal <OwnerType>;

            childItem.SetParent(default(OwnerType));
            childItem.SetIndexInParent(-1);
            SetIndexes(index + 1, index);

            base.RemoveItem(index);
        }
        protected override void InsertItem(int index, ItemType item)
        {
            bool isCancel;

            base.BeginInsertItem(index, item, out isCancel);
            if (isCancel)
            {
                return;
            }

            IChildItemInternal <OwnerType> childItem = item as IChildItemInternal <OwnerType>;

            childItem.SetIndexInParent(index);
            SetIndexes(index, index + 1);

            // NOTE: The m_Owner will be null only in deserialization, and in this case we should not call SetParent...
            if (m_Owner != null)
            {
                childItem.SetParent(m_Owner);
            }

            base.InsertItem(index, item);
        }