473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Datagrid bound to CollectionBase class doesn't use Enumerator!

Hello,

I'm trying to write a PageableCollection class which implements paging for
me so I don't need to rely on the paging provided by the DataGrid as that
generates huge viewstate when bound to a collection with a lot of items.

The code below works fine when I use foreach to iterate over it but when I
bind the Datagrid to an instance of this class I get the whole collection
displayed in the grid! Does the Datagrid not use GetEnumerator to obtain an
enumerator? I've also tried overriding the indexer and count properties of
the collection with no success.

Is the DataGrid doing something cheesy with Reflection in the case of being
bound to a class derived from CollectionBase to get directly at the
InnerList inside the collection?

Anybody got any idea what is going on here?

Thanks.
Code follows:

public class PageableCollection : CollectionBase
{
private bool fAllowPaging;
private int fPageSize;
private int fCurrentPage;

public int CurrentPage
{
get { return fCurrentPage; }
set { fCurrentPage = value; }
}

public bool AllowPaging
{
get { return fAllowPaging; }
set { fAllowPaging = value; }
}

public int PageSize
{
get { return fPageSize; }
set { fPageSize = value; }
}

public int PageCount
{
get
{
return ((Count % fPageSize) == 0) ? (Count / fPageSize) : ((Count /
fPageSize) + 1);
}
}

public PageableCollection()
{
fAllowPaging = false;
fPageSize = 20;
fCurrentPage = 1;
}

public new IEnumerator GetEnumerator()
{
if (!fAllowPaging)
return base.GetEnumerator();
else
{
int index = ((fPageSize * fCurrentPage) - fPageSize);
int count = fPageSize;

if ((count + index) > Count)
count = Count - index;

return InnerList.GetEnumerator(index, count);
}
}
Nov 15 '05 #1
0 1299

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthew Fitzpatrick | last post by:
I have a class (MyDataList) which implements CollectionBase and IBindingList. This class is bound to a data grid. Whenever my MyDataList is updated (another thread invokes updates this on the...
5
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not...
0
by: Shannon Richards | last post by:
Hello All: Can anyone tell what exactly this method is supposed to be used for? I have a class that derives from CollectionBase. This class overrides the OnSetComplete() method to raise an event...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
6
by: GingerNinja | last post by:
Hi Everybody, its about my 4th day on C# and all seems to be going smoothly however I've started to get into Datagrids and in particular binding data sources to them. In the documentation it says I...
7
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't...
1
by: Angelos Karantzalis | last post by:
Hi guys, I've an Enumerator of object arrays that I need to display on a DataGrid. Unfortunately, after I set the DataSource to the Enumerator, and call DataBind(), the DataGrid picks up &...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
2
by: Don | last post by:
I've been trying to create a custom collection that can be bound to a combobox via the DataSource property, but I can't seem to get it to work. I've created a class that implements IList, and it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.