472,809 Members | 4,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,809 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 1273

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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.