Reputation: 1560
Hello guys I have a sample gridview
Here's what i want to happen.
When I open the form i load top 100 of data from the server in to the gridview. When I scroll down and reach the end of the scroll bar I want to load another data from 101 - 200. so the data in the gridview is 1 to 200. How do I determine if the scroll bar reach the end?
Upvotes: 1
Views: 5463
Reputation: 11277
Depending on the version of XtraGrid you are using - perhaps you should check out InstantFeedback
It's a datasource that dynamicly get rows, when they come into view.
The great thing about this is - that it's a standard DevExpress component - so you don't have to invent anything youself.
OR:
You could force that behavior with some thing like this:
private bool _working = false;
private void view_RowStyle(object sender, RowStyleEventArgs e)
{
if(_working) return;
var view = sender as GridView;
if (view != null)
{
int lastRowIndex = (view.GridControl.DataSource as BindingSource).Count;
if (view.IsRowVisible(lastRowIndex) == RowVisibleState.Visible)
{
_working = true;
//go get more rows.
_working = false;
}
}
}
This assumes that you are using a BindingSource
(if not, the you must change the cast type).
I handle the RowStyle
event because the code in this event are executed "all time time".
Upvotes: 4
Reputation: 17850
You cah handle the scrolling to end (and any another conditions) via handling the Scroll
event of GridControl's embedded scrollbar.
Here is the approach details:
var sb = GetScrollBar(gridControl1, ScrollBarType.Vertical);
sb.Scroll += new ScrollEventHandler(sb_Scroll);
//...
void sb_Scroll(object sender, ScrollEventArgs e) {
var scrollBar = sender as DevExpress.XtraEditors.ScrollBarBase;
if(e.NewValue == (scrollBar.Maximum - scrollBar.LargeChange)) {
MessageBox.Show("Last row is reached!");
}
}
ScrollBarBase GetScrollBar(GridControl gridControl, ScrollBarType type) {
foreach(Control c in gridControl.Controls) {
var scrollBar = c as ScrollBarBase;
if(scrollBar != null && scrollBar.ScrollBarType == type)
return scrollBar;
}
return null;
}
Upvotes: 2
Reputation: 39
You can get the displayed rows count and calculate based on the total loaded rows and check in the TopRowChanged event and see if you need to load any more rows. This is a more manually approach for this situation.
Also you can use the grid in server mode which does this for you.
Regards, Mishu
Upvotes: 1