void LoadAutoFieldsState(Object state)
 {
     if (state != null)
     {
         Object[] fieldStates = (Object[])state;
         int count = fieldStates.Length;
         ArrayList list = new ArrayList(count);
         foreach (Object fieldState in fieldStates)
         {
             ObjectListField field = new ObjectListField();
             ((IStateManager)field).TrackViewState();
             ((IStateManager)field).LoadViewState (fieldState);
             list.Add(field);
         }
         _autoGeneratedFields = new ObjectListFieldCollection(this, list);
     }
 }
 internal void OnFieldChanged(bool fieldAddedOrRemoved)
 {
     // Called when a field is added, removed, etc.
     if (IsTrackingViewState)
     {
         _items = null;
         // avoid view state being out of [....] with fields.
         _ignoreFieldsItemsViewModeViewState = true;
         if (fieldAddedOrRemoved)
         {
             _allFields = null;
         }
         InvalidateDisplayFieldIndices();
     }
 }
        /////////////////////////////////////////////////////////////////////////
        //  FIELD AUTO-GENERATION
        /////////////////////////////////////////////////////////////////////////

        /// <include file='doc\ObjectList.uex' path='docs/doc[@for="ObjectList.CreateAutoGeneratedFields"]/*' />
        protected void CreateAutoGeneratedFields(IEnumerable dataSource)
        {
            if (dataSource == null)
            {
                return;
            }

            ArrayList list = new ArrayList();
            PropertyDescriptorCollection propertyDescriptors = null;

            if (dataSource is ITypedList)
            {
                propertyDescriptors = 
                    ((ITypedList)dataSource).GetItemProperties(new PropertyDescriptor[0]);
            }

            if (propertyDescriptors == null)
            {
                IEnumerator enumerator = dataSource.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    Object sampleItem = enumerator.Current;
                    StoreEnumerator(enumerator, sampleItem);
                    if (IsBindableType(sampleItem.GetType()))
                    {
                        list.Add(CreateAutoGeneratedField(
                                        SR.GetString(SR.ObjectList_ItemTitle), 
                                        null));
                    }
                    else
                    {
                        propertyDescriptors = TypeDescriptor.GetProperties(sampleItem);
                    }
                }
            }

            if (propertyDescriptors != null && propertyDescriptors.Count > 0)
            {
                foreach (PropertyDescriptor pd in propertyDescriptors)
                {
                    if (IsBindableType(pd.PropertyType))
                    {
                        String title;
                        ObjectListTitleAttribute attr = 
                            (ObjectListTitleAttribute)pd.Attributes[typeof(ObjectListTitleAttribute)];
                        if (attr != null)
                        {
                            title = attr.Title;
                        }
                        else
                        {
                            title = pd.Name;
                        }
                        list.Add(CreateAutoGeneratedField(title, pd.Name));
                    }
                }
            }

            _autoGeneratedFields = new ObjectListFieldCollection(this, list);
        }