Reputation: 3979
I have a DevExpress (14.2) XtraGrid with GridView
. In one column I want to show a value which is complex to generate. So I am doing this async. If I load 10000 rows for example, I don't want to start 10000 async calls for each row to generate the complex value. I thought it would be nice, if just the visible rows are getting updated. Visible means that they are actual displayed to the user.
This is what i tried so far (Datasource = List):
if (this._myDataSource != null)
{
foreach (MyObject object in this._myDataSource)
{
int rowHandle = this.myGridView.GetRowHandle(this._myDataSource.IndexOf(object));
var rowState = this.myGridView.IsRowVisible(rowHandle);
switch (rowState) {
case RowVisibleState.Visible:
object.LoadAsyncData;
break;
}
}
}
If the GridView.Layout
event fires, I execute the above code. So if the user is sorting or grouping this will be executed.
But there are some curious behaviours. Some Rows seems to be not visible at the time the event fires. Further the Layout-Event dont fire on scrolling the GridView
.
The last two rows are not loaded, but they are visible.
Someone know how to handle this and how to extend this for scrolling?
Upvotes: 1
Views: 5581
Reputation: 6621
You can get visible rows by using undocumented BaseView.GetViewInfo
method. This method return the object of BaseViewInfo
type which you need to convert to GridViewInfo
type. After that you can use GridViewInfo.RowsInfo
property to get all visible rows.
Here is example:
var info = (GridViewInfo)gridView1.GetViewInfo();
foreach (var rowInfo in info.RowsInfo)
{
int rowHandle = rowInfo.RowHandle;
if (gridView1.IsDataRow(rowHandle))
{
var dataObject = (YourDataClass)gridView1.GetRow(rowHandle);
dataObject.LoadAsyncData;
}
}
For scroll you can use GridView.TopRowChanged
event.
Upvotes: 4