Procházet zdrojové kódy

2002-09-12 Gaurav Vaish <[email protected]>

* PagedDataSource.cs   - FirstIndexInPage : Fixed bug.
* DataGrid.cs          - CreateControlHierarchy(bool)
                            : working towards completion.
    	                       - ResolveDataSource(object, string)
       	                            : stubbed new method
    	                       - CreateItem(....)
       	                            : stubbed new method
    	                Well. It's almost done.
* DataGridTableInternal.cs
                       - Added new internal class.

svn path=/trunk/mcs/; revision=7390
Gaurav Vaish před 23 roky
rodič
revize
021c2720cf

+ 13 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,16 @@
+2002-09-12      Gaurav Vaish <[email protected]>
+
+	* PagedDataSource.cs   - FirstIndexInPage : Fixed bug.
+	* DataGrid.cs          - CreateControlHierarchy(bool)
+	                            : working towards completion.
+	                       - ResolveDataSource(object, string)
+	                            : stubbed new method
+	                       - CreateItem(....)
+	                            : stubbed new method
+	                Well. It's almost done.
+	* DataGridTableInternal.cs
+	                       - Added new internal class.
+
 2002-08-28      Gaurav Vaish <[email protected]>
 
 	* DataSourceInternal.cs       - Added new class (internal).

+ 255 - 10
mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs

@@ -936,12 +936,10 @@ namespace System.Web.UI.WebControls
 			}
 		}
 
-		[MonoTODO]
 		protected override void CreateControlHierarchy(bool useDataSource)
 		{
-			IEnumerator pageSource;
+			IEnumerator pageSourceEnumerator;
 			int         itemCount;
-			int         dsItemCount;
 			ArrayList   dataKeys;
 			ArrayList   columns;
 			IEnumerable resolvedDS;
@@ -960,9 +958,8 @@ namespace System.Web.UI.WebControls
 			int         selIndex;
 
 			pagedDataSource = CreatePagedDataSource();
-			pageSource      = null;
+			pageSourceEnumerator  = null;
 			itemCount       = -1;
-			dsItemCount     = -1;
 			dataKeys        = DataKeysArray;
 			columns         = null;
 			if(itemsArrayList != null)
@@ -980,13 +977,264 @@ namespace System.Web.UI.WebControls
 				{
 					if(pagedDataSource.IsCustomPagingEnabled)
 					{
-						// I may need a dummy pagedDS
+						pagedDataSource.DataSource = new DataSourceInternal(itemCount);
+					} else
+					{
+						pagedDataSource.DataSource = new DataSourceInternal(pageDSCount);
+					}
+					pageSourceEnumerator = pagedDataSource.GetEnumerator();
+					columns              = CreateColumnSet(null, false);
+					itemsArrayList.Capacity = itemCount;
+				}
+			} else
+			{
+				dataKeys.Clear();
+				resolvedDS = ResolveDataSource(DataSource, DataMember);
+				if(resolvedDS != null)
+				{
+					collResolvedDS = (ICollection) resolvedDS;
+					if(pagedDataSource.IsPagingEnabled && !pagedDataSource.IsCustomPagingEnabled
+					   && collResolvedDS == null)
+					{
+						throw new HttpException(HttpRuntime.FormatResourceString("DataGrid_Missing_VirtualItemCount", ID));
+					}
+					pagedDataSource.DataSource = resolvedDS;
+					if(pagedDataSource.IsPagingEnabled && (pagedDataSource.CurrentPageIndex < 0 ||
+					                       pagedDataSource.CurrentPageIndex >= pagedDataSource.PageCount))
+					{
+						throw new HttpException(HttpRuntime.FormatResourceString("DataGrid_Invalid_Current_PageIndex", ID));
+					}
+					columns = CreateColumnSet(pagedDataSource, useDataSource);
+					if(storedDataValid)
+					{
+						pageSourceEnumerator = storedData;
+					} else
+					{
+						pageSourceEnumerator = pagedDataSource.GetEnumerator();
+					}
+					if(collResolvedDS != null)
+					{
+						pageDSCount         = pagedDataSource.Count;
+						dataKeys.Capacity   = pageDSCount;
+						itemsArrayList.Capacity = pageDSCount;
+					}
+				}
+				colCount = 0;
+				if(columns != null)
+					colCount = columns.Count;
+				int currentSourceIndex;
+				if(colCount > 0)
+				{
+					cols = new DataGridColumn[colCount];
+					columns.CopyTo(cols, 0);
+					foreach(DataGridColumn current in cols)
+					{
+						cols.Initialize();
+					}
+					deployTable = new DataGridTableInternal();
+					Controls.Add(deployTable);
+					deployRows = deployTable.Rows;
+
+					indexCounter = 0;
+					currentSourceIndex  = 0;
+					dkField = DataKeyField;
+
+					dsUse = (useDataSource) ? (dkField.Length > 0) : false;
+					pgEnabled = pagedDataSource.IsPagingEnabled;
+					editIndex = EditItemIndex;
+					selIndex  = SelectedIndex;
+					if(pgEnabled)
+					{
+						currentSourceIndex = pagedDataSource.FirstIndexInPage;
+						CreateItem(-1, -1, ListItemType.Pager, false, null,
+						           cols, deployRows, pagedDataSource);
+					}
+					itemCount = 0;
+					CreateItem(-1, -1, ListItemType.Header, useDataSource, null,
+					           cols, deployRows, null);
+					if(storedDataValid && storedDataFirst != null)
+					{
+						if(dsUse)
+						{
+							dataKeys.Add(DataBinder.GetPropertyValue(storedDataFirst, dkField));
+						}
+						deployType = ListItemType.Item;
+						if(indexCounter == editIndex)
+						{
+							deployType = ListItemType.EditItem;
+						} else if(indexCounter == selIndex)
+						{
+							deployType = ListItemType.SelectedItem;
+						}
+						itemsArrayList.Add(CreateItem(0, currentSourceIndex, deployType,
+						                              useDataSource, storedDataFirst,
+						                              cols, deployRows, null));
+						itemCount++;
+						indexCounter++;
+						currentSourceIndex++;
+						storedDataValid = false;
+						storedDataFirst = null;
+					}
+
+					while(pageSourceEnumerator.MoveNext())
+					{
+						object current = pageSourceEnumerator.Current;
+						if(dsUse)
+						{
+							dataKeys.Add(DataBinder.GetPropertyValue(current, dkField));
+						}
+						deployType = ListItemType.Item;
+						if(indexCounter == editIndex)
+						{
+							deployType = ListItemType.EditItem;
+						} else if(indexCounter == selIndex)
+						{
+							deployType = ListItemType.SelectedItem;
+						}
+						itemsArrayList.Add(CreateItem(indexCounter, currentSourceIndex,
+						                              deployType, useDataSource, current,
+						                              cols, deployRows, null));
+						itemCount++;
+						indexCounter++;
+						currentSourceIndex++;
+					}
+
+					if(pgEnabled)
+					{
+						CreateItem(-1, -1, ListItemType.Pager, false, null, cols, deployRows,
+						           pagedDataSource);
+					}
+				}
+
+				if(useDataSource)
+				{
+					if(pageSourceEnumerator != null)
+					{
+						ViewState["_DataGrid_ItemCount"] = itemCount;
+						if(pagedDataSource.IsPagingEnabled)
+						{
+							ViewState["PageCount"] = pagedDataSource.PageCount;
+							ViewState["DataGrid_DataSource_Count"] = pagedDataSource.DataSourceCount;
+						} else
+						{
+							ViewState["PageCount"] = 1;
+							ViewState["DataGrid_DataSource_Count"] = itemCount;
+						}
+					} else
+					{
+						ViewState["_DataGrid_ItemCount"] = -1;
+						ViewState["DataGrid_DataSource_Count"] = -1;
+						ViewState["PageCount"] = 0;
 					}
 				}
+			}
+			pagedDataSource = null;
+		}
+
+		private IEnumerable ResolveDataSource(object source, string member)
+		{
+			if(source != null && source is IListSource)
+			{
+				IListSource src = (IListSource)source;
+				IList list = src.GetList();
+				if(!src.ContainsListCollection)
+				{
+					return list;
+				}
+				if(list != null && list is ITypedList)
+				{
+					ITypedList tlist = (ITypedList)list;
+					PropertyDescriptorCollection pdc = tlist.GetItemProperties(new PropertyDescriptor[0]);
+					if(pdc != null && pdc.Count > 0)
+					{
+						PropertyDescriptor pd = null;
+						if(member != null && member.Length > 0)
+						{
+							pd = pdc.Find(member, true);
+						} else
+						{
+							pd = pdc[0];
+						}
+						if(pd != null)
+						{
+							object rv = pd.GetValue(list[0]);
+							if(rv != null && rv is IEnumerable)
+							{
+								return (IEnumerable)rv;
+							}
+						}
+						throw new HttpException(
+						      HttpRuntime.FormatResourceString("ListSource_Missing_DataMember", member));
+					}
+					throw new HttpException(
+					      HttpRuntime.FormatResourceString("ListSource_Without_DataMembers"));
+				}
+			}
+			if(source is IEnumerable)
+			{
+				return (IEnumerable)source;
+			}
+			return null;
+		}
+
+		[MonoTODO]
+		private DataGridItem CreateItem(int itemIndex, int dsIndex, ListItemType type,
+		                                bool bind, object item, DataGridColumn[] columns,
+		                                TableRowCollection rows, PagedDataSource dataSrc)
+
+		{
+			DataGridItem retVal;
+			DataGridItemEventArgs args;
+
+			retVal = CreateItem(itemIndex, dsIndex, type);
+			args = new DataGridItemEventArgs(retVal);
+
+			if(type != ListItemType.Pager)
+			{
+				InitializeItem(retVal, columns);
+				if(bind)
+				{
+					retVal.DataItem = item;
+				}
+				OnItemCreated(args);
+				rows.Add(retVal);
+				if(bind)
+				{
+					retVal.DataBind();
+					OnItemDataBound(args);
+					retVal.DataItem = null;
+				}
 			} else
 			{
-				//TODO: Use Data Source
+				InitializePager(retVal, columns);
+				OnItemCreated(args);
+				rows.Add(retVal);
 			}
+			return retVal;
+		}
+
+		protected virtual DataGridItem CreateItem(int itemIndex, int dataSourceIndex, ListItemType itemType)
+		{
+			return new DataGridItem(itemIndex, dataSourceIndex, itemType);
+		}
+
+		[MonoTODO]
+		protected virtual void InitializeItem(DataGridItem item, DataGridColumn[] columns)
+		{
+			TableCellCollection cells = item.Cells;
+			TableCell cCell;
+			
+			for(int i = 0; i < columns.Length; i++)
+			{
+				cCell = new TableCell();
+				columns[i].InitializeCell(cCell, i, item.ItemType);
+				cells.Add(cCell);
+			}
+		}
+
+		[MonoTODO]
+		protected virtual void InitializePager(DataGridItem item, DataGridColumn[] columns)
+		{
 			throw new NotImplementedException();
 		}
 
@@ -1051,7 +1299,6 @@ namespace System.Web.UI.WebControls
 			if(source != null)
 			{
 				ArrayList retVal = new ArrayList();
-				bool      flag   = true;
 				PropertyDescriptorCollection props = source.GetItemProperties(new PropertyDescriptor[0]);
 				Type      prop_type;
 				BoundColumn b_col;
@@ -1072,8 +1319,6 @@ namespace System.Web.UI.WebControls
 						IEnumerator en = source.GetEnumerator();
 						if(en.MoveNext())
 							fitem = en.Current;
-						else
-							flag = false;
 						if(fitem != null)
 						{
 							prop_type = fitem.GetType();

+ 31 - 0
mcs/class/System.Web/System.Web.UI.WebControls/DataGridTableInternal.cs

@@ -0,0 +1,31 @@
+/**
+ * Namespace:   System.Web.UI.WebControls
+ * Class:       DataGridTableInternal
+ *
+ * Author:      Gaurav Vaish
+ * Maintainer:  [email protected]
+ *
+ * (C) Gaurav Vaish (2002)
+ */
+
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+	public class DataGridTableInternal : Table
+	{
+		public DataGridTableInternal() : base()
+		{
+		}
+
+		protected override void AddAttributesToRender(HtmlTextWriter writer)
+		{
+			base.AddAttributesToRender(writer);
+			if(ID == null)
+			{
+				writer.AddAttribute(HtmlTextWriterAttribute.Id, Parent.ClientID);
+			}
+		}
+	}
+}

+ 475 - 475
mcs/class/System.Web/System.Web.UI.WebControls/PagedDataSource.cs

@@ -1,475 +1,475 @@
-/**
- * Namespace: System.Web.UI.WebControls
- * Class:     PagedDataSource
- *
- * Author:  Gaurav Vaish
- * Maintainer: [email protected]
- * Contact: <[email protected]>, <[email protected]>
- * Implementation: yes
- * Status:  100%
- *
- * (C) Gaurav Vaish (2002)
- */
-
-using System;
-using System.ComponentModel;
-using System.Collections;
-using System.Web;
-using System.Web.UI;
-
-namespace System.Web.UI.WebControls
-{
-	public sealed class PagedDataSource : ICollection, IEnumerable, ITypedList
-	{
-		private int  pageSize;
-		private bool allowPaging;
-		private int  currentPageIndex;
-		private bool allowCustomPaging;
-		private int  virtualCount;
-
-		private IEnumerable dataSource;
-
-		public PagedDataSource()
-		{
-			Initialize();
-		}
-
-		private void Initialize()
-		{
-			pageSize          = 10;
-			allowPaging       = false;
-			currentPageIndex  = 0;
-			allowCustomPaging = false;
-			virtualCount      = 0;
-		}
-
-		public bool AllowCustomPaging
-		{
-			get
-			{
-				return allowCustomPaging;
-			}
-			set
-			{
-				allowCustomPaging = value;
-			}
-		}
-
-		public bool AllowPaging
-		{
-			get
-			{
-				return allowPaging;
-			}
-			set
-			{
-				allowPaging = value;
-			}
-		}
-
-		public int Count
-		{
-			get
-			{
-				if(dataSource != null)
-				{
-					if(IsPagingEnabled)
-					{
-						return DataSourceCount;
-					}
-					if(IsCustomPagingEnabled)
-					{
-						return pageSize;
-					}
-					if(IsLastPage)
-					{
-						return (DataSourceCount - FirstIndexInPage);
-					}
-					return pageSize;
-				}
-				return 0;
-			}
-		}
-
-		public int CurrentPageIndex
-		{
-			get
-			{
-				return currentPageIndex;
-			}
-
-			set
-			{
-				currentPageIndex = value;
-			}
-		}
-
-		public IEnumerable DataSource
-		{
-			get
-			{
-				return dataSource;
-			}
-			set
-			{
-				dataSource = value;
-			}
-		}
-
-		public int DataSourceCount
-		{
-			get
-			{
-				if(dataSource != null)
-				{
-					if(IsCustomPagingEnabled)
-					{
-						return virtualCount;
-					}
-					if(dataSource is ICollection)
-					{
-						return ((ICollection)dataSource).Count;
-					}
-					throw new HttpException(HttpRuntime.FormatResourceString("PagedDataSource_Cannot_Get_Count"));
-				}
-				return 0;
-			}
-		}
-
-		public int FirstIndexInPage
-		{
-			get
-			{
-				if(dataSource != null && IsPagingEnabled && IsCustomPagingEnabled)
-				{
-					return (currentPageIndex * pageSize);
-				}
-				return 0;
-			}
-		}
-
-		public bool IsCustomPagingEnabled
-		{
-			get
-			{
-				return (IsPagingEnabled && allowCustomPaging);
-			}
-		}
-
-		public bool IsFirstPage
-		{
-			get
-			{
-				return (!IsPagingEnabled || (CurrentPageIndex == 0));
-			}
-		}
-
-		public bool IsLastPage
-		{
-			get
-			{
-				return (!IsPagingEnabled || (CurrentPageIndex == PageCount));
-			}
-		}
-
-		public bool IsPagingEnabled
-		{
-			get
-			{
-				return (allowPaging && pageSize != 0);
-			}
-		}
-
-		public bool IsReadOnly
-		{
-			get
-			{
-				return false;
-			}
-		}
-
-		public bool IsSynchronized
-		{
-			get
-			{
-				return false;
-			}
-		}
-
-		public int PageCount
-		{
-			get
-			{
-				if(dataSource != null)
-				{
-					int total = DataSourceCount;
-					if(!IsPagingEnabled)
-					{
-						return total;
-					}
-					return (total + pageSize - 1)/pageSize;
-				}
-				return 0;
-			}
-		}
-
-		public int PageSize
-		{
-			get
-			{
-				return pageSize;
-			}
-			set
-			{
-				pageSize = value;
-			}
-		}
-
-		public object SyncRoot
-		{
-			get
-			{
-				return this;
-			}
-		}
-
-		public int VirtualCount
-		{
-			get
-			{
-				return virtualCount;
-			}
-			set
-			{
-				virtualCount = value;
-			}
-		}
-
-		public void CopyTo(Array array, int index)
-		{
-			foreach(object current in this)
-			{
-				array.SetValue(array, index++);
-			}
-		}
-
-		public IEnumerator GetEnumerator()
-		{
-			int fInd = FirstIndexInPage;
-			int count = -1;
-			if(dataSource is ICollection)
-			{
-				count = Count;
-			}
-
-			if(dataSource is IList)
-			{
-				return (new PrivateListEnumerator((IList)dataSource, fInd, count));
-			}
-			if(dataSource is Array)
-			{
-				return (new PrivateArrayEnumerator((object[])dataSource, fInd, count));
-			}
-			if(dataSource is ICollection)
-			{
-				return (new PrivateICollectionEnumerator((ICollection)dataSource, fInd, count));
-			}
-			if(allowCustomPaging)
-			{
-				return (new PrivateIEnumeratorEnumerator(dataSource.GetEnumerator(), Count));
-			}
-			return dataSource.GetEnumerator();
-		}
-
-		class PrivateIEnumeratorEnumerator : IEnumerator
-		{
-			private int index;
-			private int max;
-
-			private IEnumerator enumerator;
-
-			public PrivateIEnumeratorEnumerator(IEnumerator enumerator, int count)
-			{
-				this.enumerator = enumerator;
-				index = -1;
-				max   = count;
-			}
-
-			public bool MoveNext()
-			{
-				enumerator.MoveNext();
-				index++;
-				return (index < max);
-			}
-
-			public void Reset()
-			{
-				index = -1;
-				enumerator.Reset();
-			}
-
-			public object Current
-			{
-				get
-				{
-					return enumerator.Current;
-				}
-			}
-		}
-
-		class PrivateICollectionEnumerator : IEnumerator
-		{
-			private int index;
-			private int start;
-			private int max;
-
-			private ICollection collection;
-			private IEnumerator collEnum;
-
-			public PrivateICollectionEnumerator(ICollection collection, int start, int count)
-			{
-				this.collection = collection;
-				this.start  = start;
-				index = -1;
-				max = start + count;
-				if(max > collection.Count)
-				{
-					max = collection.Count;
-				}
-			}
-
-			public bool MoveNext()
-			{
-				if(collEnum == null)
-				{
-					int cIndex = 0;
-					collEnum = collection.GetEnumerator();
-					while(cIndex < start)
-					{
-						collEnum.MoveNext();
-					}
-				}
-				collEnum.MoveNext();
-				index++;
-				return (start + index < max);
-			}
-
-			public void Reset()
-			{
-				index = -1;
-				collEnum = null;
-			}
-
-			public object Current
-			{
-				get
-				{
-					return collEnum.Current;
-				}
-			}
-		}
-
-		class PrivateArrayEnumerator : IEnumerator
-		{
-			private int index;
-			private int start;
-			private int max;
-			private object[] values;
-
-			public PrivateArrayEnumerator(object[] values, int start, int count)
-			{
-				this.values = values;
-				this.start  = start;
-				index = -1;
-				max = start + count;
-				if(max > this.values.Length)
-				{
-					max = this.values.Length;
-				}
-			}
-
-			public bool MoveNext()
-			{
-				index++;
-				return (index + start < max);
-			}
-
-			public void Reset()
-			{
-				index = -1;
-			}
-
-			public object Current
-			{
-				get
-				{
-					if(index >= 0)
-					{
-						return values[index + start];
-					}
-					throw new InvalidOperationException("Enumerator_MoveNext_Not_Called");
-				}
-			}
-		}
-
-		class PrivateListEnumerator : IEnumerator
-		{
-			private int   index;
-			private int   start;
-			private int   max;
-			private IList collection;
-
-			public PrivateListEnumerator(IList list, int start, int count)
-			{
-				collection = list;
-				this.start = start;
-				index = -1;
-				max = start + count;
-				if(max > list.Count)
-				{
-					max = list.Count;
-				}
-			}
-
-			public bool MoveNext()
-			{
-				index++;
-				return (index + start < max);
-			}
-
-			public void Reset()
-			{
-				index = -1;
-			}
-
-			public object Current
-			{
-				get
-				{
-					if(index >= 0)
-					{
-						return collection[index + start];
-					}
-					throw new InvalidOperationException("Enumerator_MoveNext_Not_Called");
-				}
-			}
-		}
-
-		public string GetListName(PropertyDescriptor[] listAccessors)
-		{
-			return String.Empty;
-		}
-
-		public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
-		{
-			if(dataSource != null)
-			{
-				if(dataSource is ITypedList)
-				{
-					return ((ITypedList)dataSource).GetItemProperties(listAccessors);
-				}
-			}
-			return null;
-		}
-	}
-}
+/**
+ * Namespace: System.Web.UI.WebControls
+ * Class:     PagedDataSource
+ *
+ * Author:  Gaurav Vaish
+ * Maintainer: [email protected]
+ * Contact: <[email protected]>, <[email protected]>
+ * Implementation: yes
+ * Status:  100%
+ *
+ * (C) Gaurav Vaish (2002)
+ */
+
+using System;
+using System.ComponentModel;
+using System.Collections;
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+	public sealed class PagedDataSource : ICollection, IEnumerable, ITypedList
+	{
+		private int  pageSize;
+		private bool allowPaging;
+		private int  currentPageIndex;
+		private bool allowCustomPaging;
+		private int  virtualCount;
+
+		private IEnumerable dataSource;
+
+		public PagedDataSource()
+		{
+			Initialize();
+		}
+
+		private void Initialize()
+		{
+			pageSize          = 10;
+			allowPaging       = false;
+			currentPageIndex  = 0;
+			allowCustomPaging = false;
+			virtualCount      = 0;
+		}
+
+		public bool AllowCustomPaging
+		{
+			get
+			{
+				return allowCustomPaging;
+			}
+			set
+			{
+				allowCustomPaging = value;
+			}
+		}
+
+		public bool AllowPaging
+		{
+			get
+			{
+				return allowPaging;
+			}
+			set
+			{
+				allowPaging = value;
+			}
+		}
+
+		public int Count
+		{
+			get
+			{
+				if(dataSource != null)
+				{
+					if(IsPagingEnabled)
+					{
+						return DataSourceCount;
+					}
+					if(IsCustomPagingEnabled)
+					{
+						return pageSize;
+					}
+					if(IsLastPage)
+					{
+						return (DataSourceCount - FirstIndexInPage);
+					}
+					return pageSize;
+				}
+				return 0;
+			}
+		}
+
+		public int CurrentPageIndex
+		{
+			get
+			{
+				return currentPageIndex;
+			}
+
+			set
+			{
+				currentPageIndex = value;
+			}
+		}
+
+		public IEnumerable DataSource
+		{
+			get
+			{
+				return dataSource;
+			}
+			set
+			{
+				dataSource = value;
+			}
+		}
+
+		public int DataSourceCount
+		{
+			get
+			{
+				if(dataSource != null)
+				{
+					if(IsCustomPagingEnabled)
+					{
+						return virtualCount;
+					}
+					if(dataSource is ICollection)
+					{
+						return ((ICollection)dataSource).Count;
+					}
+					throw new HttpException(HttpRuntime.FormatResourceString("PagedDataSource_Cannot_Get_Count"));
+				}
+				return 0;
+			}
+		}
+
+		public int FirstIndexInPage
+		{
+			get
+			{
+				if(dataSource != null && IsPagingEnabled && !IsCustomPagingEnabled)
+				{
+					return (currentPageIndex * pageSize);
+				}
+				return 0;
+			}
+		}
+
+		public bool IsCustomPagingEnabled
+		{
+			get
+			{
+				return (IsPagingEnabled && allowCustomPaging);
+			}
+		}
+
+		public bool IsFirstPage
+		{
+			get
+			{
+				return (!IsPagingEnabled || (CurrentPageIndex == 0));
+			}
+		}
+
+		public bool IsLastPage
+		{
+			get
+			{
+				return (!IsPagingEnabled || (CurrentPageIndex == PageCount));
+			}
+		}
+
+		public bool IsPagingEnabled
+		{
+			get
+			{
+				return (allowPaging && pageSize != 0);
+			}
+		}
+
+		public bool IsReadOnly
+		{
+			get
+			{
+				return false;
+			}
+		}
+
+		public bool IsSynchronized
+		{
+			get
+			{
+				return false;
+			}
+		}
+
+		public int PageCount
+		{
+			get
+			{
+				if(dataSource != null)
+				{
+					int total = DataSourceCount;
+					if(!IsPagingEnabled)
+					{
+						return total;
+					}
+					return (total + pageSize - 1)/pageSize;
+				}
+				return 0;
+			}
+		}
+
+		public int PageSize
+		{
+			get
+			{
+				return pageSize;
+			}
+			set
+			{
+				pageSize = value;
+			}
+		}
+
+		public object SyncRoot
+		{
+			get
+			{
+				return this;
+			}
+		}
+
+		public int VirtualCount
+		{
+			get
+			{
+				return virtualCount;
+			}
+			set
+			{
+				virtualCount = value;
+			}
+		}
+
+		public void CopyTo(Array array, int index)
+		{
+			foreach(object current in this)
+			{
+				array.SetValue(array, index++);
+			}
+		}
+
+		public IEnumerator GetEnumerator()
+		{
+			int fInd = FirstIndexInPage;
+			int count = -1;
+			if(dataSource is ICollection)
+			{
+				count = Count;
+			}
+
+			if(dataSource is IList)
+			{
+				return (new PrivateListEnumerator((IList)dataSource, fInd, count));
+			}
+			if(dataSource is Array)
+			{
+				return (new PrivateArrayEnumerator((object[])dataSource, fInd, count));
+			}
+			if(dataSource is ICollection)
+			{
+				return (new PrivateICollectionEnumerator((ICollection)dataSource, fInd, count));
+			}
+			if(allowCustomPaging)
+			{
+				return (new PrivateIEnumeratorEnumerator(dataSource.GetEnumerator(), Count));
+			}
+			return dataSource.GetEnumerator();
+		}
+
+		class PrivateIEnumeratorEnumerator : IEnumerator
+		{
+			private int index;
+			private int max;
+
+			private IEnumerator enumerator;
+
+			public PrivateIEnumeratorEnumerator(IEnumerator enumerator, int count)
+			{
+				this.enumerator = enumerator;
+				index = -1;
+				max   = count;
+			}
+
+			public bool MoveNext()
+			{
+				enumerator.MoveNext();
+				index++;
+				return (index < max);
+			}
+
+			public void Reset()
+			{
+				index = -1;
+				enumerator.Reset();
+			}
+
+			public object Current
+			{
+				get
+				{
+					return enumerator.Current;
+				}
+			}
+		}
+
+		class PrivateICollectionEnumerator : IEnumerator
+		{
+			private int index;
+			private int start;
+			private int max;
+
+			private ICollection collection;
+			private IEnumerator collEnum;
+
+			public PrivateICollectionEnumerator(ICollection collection, int start, int count)
+			{
+				this.collection = collection;
+				this.start  = start;
+				index = -1;
+				max = start + count;
+				if(max > collection.Count)
+				{
+					max = collection.Count;
+				}
+			}
+
+			public bool MoveNext()
+			{
+				if(collEnum == null)
+				{
+					int cIndex = 0;
+					collEnum = collection.GetEnumerator();
+					while(cIndex < start)
+					{
+						collEnum.MoveNext();
+					}
+				}
+				collEnum.MoveNext();
+				index++;
+				return (start + index < max);
+			}
+
+			public void Reset()
+			{
+				index = -1;
+				collEnum = null;
+			}
+
+			public object Current
+			{
+				get
+				{
+					return collEnum.Current;
+				}
+			}
+		}
+
+		class PrivateArrayEnumerator : IEnumerator
+		{
+			private int index;
+			private int start;
+			private int max;
+			private object[] values;
+
+			public PrivateArrayEnumerator(object[] values, int start, int count)
+			{
+				this.values = values;
+				this.start  = start;
+				index = -1;
+				max = start + count;
+				if(max > this.values.Length)
+				{
+					max = this.values.Length;
+				}
+			}
+
+			public bool MoveNext()
+			{
+				index++;
+				return (index + start < max);
+			}
+
+			public void Reset()
+			{
+				index = -1;
+			}
+
+			public object Current
+			{
+				get
+				{
+					if(index >= 0)
+					{
+						return values[index + start];
+					}
+					throw new InvalidOperationException("Enumerator_MoveNext_Not_Called");
+				}
+			}
+		}
+
+		class PrivateListEnumerator : IEnumerator
+		{
+			private int   index;
+			private int   start;
+			private int   max;
+			private IList collection;
+
+			public PrivateListEnumerator(IList list, int start, int count)
+			{
+				collection = list;
+				this.start = start;
+				index = -1;
+				max = start + count;
+				if(max > list.Count)
+				{
+					max = list.Count;
+				}
+			}
+
+			public bool MoveNext()
+			{
+				index++;
+				return (index + start < max);
+			}
+
+			public void Reset()
+			{
+				index = -1;
+			}
+
+			public object Current
+			{
+				get
+				{
+					if(index >= 0)
+					{
+						return collection[index + start];
+					}
+					throw new InvalidOperationException("Enumerator_MoveNext_Not_Called");
+				}
+			}
+		}
+
+		public string GetListName(PropertyDescriptor[] listAccessors)
+		{
+			return String.Empty;
+		}
+
+		public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
+		{
+			if(dataSource != null)
+			{
+				if(dataSource is ITypedList)
+				{
+					return ((ITypedList)dataSource).GetItemProperties(listAccessors);
+				}
+			}
+			return null;
+		}
+	}
+}