views:

204

answers:

2

I have a WinForm DataGridView bound to a List<> of objects and I would like to set the datasource of the DataGridView to display only so many records at a time. From a few searches it looks like there is a way to do this however I have not found the exact method. Is there a way to set the total row count and then set an event that fires when more rows are needed? I am thinking that I need to do something like:

private const int AMOUNT = 1000;
private int pageCount = 0;
this.grdItems.VirtualMode = true;

// Initial Load
this.grdItems.RowCount = myList.Count();
this.grdItems.DataSource = myList.Take(AMOUNT);

// When the user scrolls to the bottom of the list
this.grdItems.DataSource = myList.Skip(pageCount++).Take(AMOUNT);
+1  A: 

See this MSDN article

Christopher Edwards
I tried something similar however I can't get the CellValueNeeded or the NewRowNeeded events to fire.
jwarzech
Can you post your code and I'll have a look, it's worked for me in the past...
Christopher Edwards
A: 

You need to set VirtualMode =true to get it working

Paresh