/// <include file='doc\ObjectListFieldCollection.uex' path='docs/doc[@for="ObjectListFieldCollection.AddAt"]/*' />
 public void AddAt(int index, ObjectListField field)
 {
     if (index == -1)
     {
         Items.Add(field);
     }
     else
     {
         Items.Insert(index, field);
     }
     if (_marked)
     {
         if (!_fieldsSetDirty && index > -1)
         {
             SetFieldsDirty();
         }
         else
         {
             ((IStateManager)field).TrackViewState();
             field.SetDirty();
         }
     }
     field.SetOwner(_owner);
     NotifyOwnerChange();
 }
        private void EnsureCount(int count)
        {
            int diff = Count - count;

            if (diff > 0)
            {
                Items.RemoveRange(count, diff);
                NotifyOwnerChange();
            }
            else
            {
                // Set owner = null, to avoid multiple change notifications.
                // We'll call it just once later.

                ObjectList prevOwner = _owner;
                _owner = null;
                for (int i = diff; i < 0; i++)
                {
                    ObjectListField field = new ObjectListField();
                    Add(field);
                    field.SetOwner(prevOwner);
                }
                _owner = prevOwner;
                NotifyOwnerChange();
            }
        }
 /// <include file='doc\ObjectListFieldCollection.uex' path='docs/doc[@for="ObjectListFieldCollection.AddAt"]/*' />
 public void AddAt(int index, ObjectListField field)
 {
     if (index == -1)
     {
         Items.Add(field);
     }
     else
     {
         Items.Insert(index, field);
     }
     if (_marked)
     {
         if (!_fieldsSetDirty && index > -1)
         {
             SetFieldsDirty();
         }
         else
         {
             ((IStateManager)field).TrackViewState();
             field.SetDirty();
         }
     }
     field.SetOwner(_owner);
     NotifyOwnerChange();
 }
        private void EnsureCount(int count)
        {

            int diff = Count - count;
            if (diff > 0)
            {
                Items.RemoveRange(count, diff);
                NotifyOwnerChange();
            }
            else
            {
                // Set owner = null, to avoid multiple change notifications. 
                // We'll call it just once later.

                ObjectList prevOwner = _owner;
                _owner = null;
                for (int i = diff; i < 0; i++)
                {
                    ObjectListField field = new ObjectListField();
                    Add(field);
                    field.SetOwner(prevOwner);
                }
                _owner = prevOwner;
                NotifyOwnerChange();
            }
        }