Back to Devexpress

InfiniteAsyncSource.FetchRows Event

wpf-devexpress-dot-xpf-dot-data-dot-infiniteasyncsource-4520695f.md

latest9.4 KB
Original Source

InfiniteAsyncSource.FetchRows Event

Allows you to fetch rows.

Namespace : DevExpress.Xpf.Data

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public event EventHandler<FetchRowsAsyncEventArgs> FetchRows
vb
Public Event FetchRows As EventHandler(Of FetchRowsAsyncEventArgs)

Event Data

The FetchRows event's data class is FetchRowsAsyncEventArgs. The following properties provide information specific to this event:

PropertyDescription
AllowRetryGets or sets whether re-requesting data is allowed. Inherited from FetchRowsEventArgsBase.
FilterGets the GridControl filtering. Inherited from FetchEventArgsBase.
KeysGets keys that you passed to the ReloadRows(Object[]) method.
ResultGets or sets the result of the fetch rows operation.
SkipGets the number of rows to skip in a returned result set. Inherited from FetchEventArgsBase.
SkipTokenGets the skip token. Inherited from FetchEventArgsBase.
SortOrderGets the GridControl‘s sorting. Inherited from FetchEventArgsBase.
Take

Gets the number of rows within and above the viewport that are reloaded when you call the RefreshRows method or users press F5.

null when the grid fetches next portion of data (a user scrolls rows).

int.Max when you call the InfiniteAsyncSource.ReloadRows / PagedAsyncSource.ReloadRows method.

Inherited from FetchRowsEventArgsBase. |

Remarks

View Example: How to Bind to InfiniteAsyncSource

To fetch rows from the data source:

csharp
public MainWindow() {
    // ...
    source.FetchRows += (o, e) => {
        e.Result = FetchRowsAsync(e);
    };
}
static async Task<FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e) {
  IssueSortOrder sortOrder = GetIssueSortOrder(e);
  IssueFilter filter = MakeIssueFilter(e.Filter);
  var take = e.Take ?? 30;
  var issues = await IssuesService.GetIssuesAsync(
    skip: e.Skip,
    take: take,
    sortOrder: sortOrder,
    filter: filter);
  return new FetchRowsResult(issues, hasMoreRows: issues.Length == take);
}
static IssueSortOrder GetIssueSortOrder(FetchRowsAsyncEventArgs e) {
    return IssueSortOrder.Default;
}
static IssueFilter MakeIssueFilter(CriteriaOperator filter) {
    return null;
}

The FetchRowsEventArgsBase.Take property returns the number of rows that should be reloaded. Use this property to allow the InfiniteAsyncSource to retain a selected row and scroll position after refresh. The PagedAsyncSource automatically retains a selected row and scroll position.

If data in your source are changed frequently, you can retain the same selected row after refresh. Specify the VirtualSourceBase.KeyProperty property to make a virtual source find the selected row by a specific field.

If you want to maintain a clean MVVM pattern and specify a fetch operation in a ViewModel, create a command and bind it to the InfiniteAsyncSource.FetchRowsCommand property.

The following code snippets (auto-collected from DevExpress Examples) contain references to the FetchRows event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-bind-wpf-grid-to-data/CS/CodeBehind/EFCore/InfiniteAsyncSource/MainWindow.xaml.cs#L20

csharp
};
source.FetchRows += OnFetchRows;
source.GetTotalSummaries += OnGetTotalSummaries;

wpf-data-grid-implement-crud-operations/CS/CodeBehind/EFCore/InfiniteAsyncSource/MainWindow.xaml.cs#L20

csharp
};
source.FetchRows += OnFetchRows;
source.GetTotalSummaries += OnGetTotalSummaries;

wpf-data-grid-use-skip-tokens-to-optimize-paging-EF/CS/MainWindow.xaml.cs#L21

csharp
source.FetchRows += (o, e) => {
    e.Result = Task.Run(() => FetchRows(e));

wpf-data-grid-bind-to-custom-service-with-restrictions/CS/MainWindow.xaml.cs#L23

csharp
source.FetchRows += (o, e) => {
    e.Result = FetchRowsAsync(e);

wpf-data-grid-use-virtual-sources-to-bind-to-in-memory-data/CS/MainWindow.xaml.cs#L29

csharp
source.FetchRows += (o, e) => {
    e.Result = FetchRows(e, getSourceTask);

how-to-bind-wpf-grid-to-data/VB/CodeBehind/EFCore/InfiniteAsyncSource/MainWindow.xaml.vb#L17

vb
}
AddHandler source.FetchRows, AddressOf OnFetchRows
AddHandler source.GetTotalSummaries, AddressOf OnGetTotalSummaries

wpf-data-grid-use-skip-tokens-to-optimize-paging-EF/VB/MainWindow.xaml.vb#L17

vb
AddHandler Unloaded, Sub(o, e) source.Dispose()
AddHandler source.FetchRows, Sub(o, e)
    e.Result = Task.Run(Function() FetchRows(e))

wpf-data-grid-bind-to-custom-service-with-restrictions/VB/MainWindow.xaml.vb#L19

vb
AddHandler Unloaded, Sub(o, e) source.Dispose()
AddHandler source.FetchRows, Sub(o, e) e.Result = FetchRowsAsync(e)
AddHandler source.GetUniqueValues, Sub(o, e) e.Result = GetUniqueValuesAsync(e.PropertyName)

wpf-data-grid-use-virtual-sources-to-bind-to-in-memory-data/VB/MainWindow.xaml.vb#L20

vb
Dim getSourceTask = Task.Run(Function() Enumerable.Range(0, 10000000).[Select](Function(i) CreateIssue()).ToList())
AddHandler source.FetchRows, Sub(o, e) e.Result = FetchRows(e, getSourceTask)
AddHandler source.GetTotalSummaries, Sub(o, e) e.Result = GetTotalSummaries(e, getSourceTask)

See Also

FetchMoreRows()

InfiniteAsyncSource Class

InfiniteAsyncSource Members

DevExpress.Xpf.Data Namespace