Skip to main content

InfiniteAsyncSource.ReloadRows(Object[]) Method

Reloads rows with specified keys.

Namespace: DevExpress.Xpf.Data

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

NuGet Package: DevExpress.Wpf.Core

Declaration

public void ReloadRows(
    params object[] keys
)

Parameters

Name Type Description
keys Object[]

Key field values that identify the rows you want to reload.

Remarks

Tip

Use the ReloadRows method to reload a subset of grid data. To refresh data in all rows, call the VirtualSourceBase.RefreshRows method.

Before you use the ReloadRows method, make sure that the virtual source’s KeyProperty specifies a key field. The code sample below sets this property to the Id field. The ReloadRows method then accepts an array of key values that identify the rows to be reloaded:

private void Button_Click(object sender, RoutedEventArgs e) {
    int[] selectedRowIds = grid.SelectedItems.Cast<IssueData>().Select(x => x.Id).ToArray();
    ((InfiniteAsyncSource)(grid.ItemsSource)).ReloadRows(selectedRowIds);
}

// ...

var source = new InfiniteAsyncSource() {
    ElementType = typeof(IssueData),
    KeyProperty = nameof(IssueData.Id)
};

The ReloadRows method raises the FetchRows event. In the event handler, process the keys that you passed to the ReloadRows method. Use one of the following approaches:

  • Use the e.Keys property to get the keys. Return rows that correspond to these keys.

    static async Task<FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e) {
        if(e.Keys != null) {
            var reloadedIssues = await IssuesService.GetIssuesById(e.Keys.Cast<int>().ToArray());
            return new FetchRowsResult(reloadedIssues);
        }
        // ...
    }
    
  • Use the e.Filter property to identify rows using a filter object. The filter contains an InOperator constructed from the keys you passed to the ReloadRows method. Parse the filter and return rows.

    static async Task<FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e) {
        var take = e.Take ?? 30;
        var issues = await IssuesService.GetIssuesAsync(
            skip: e.Skip,
            take: take,
            sortOrder: IssueSortOrder.Default,
            filter: MakeIssueFilter(e.Filter));
        return new FetchRowsResult(issues, hasMoreRows: issues.Length == take);
    }
    
    static IssueFilter MakeIssueFilter(CriteriaOperator filter) {
        return filter.Match(
            // ...
            @in: (propertyName, values) => {
                if (propertyName == nameof(IssueData.Id))
                    return new IssueFilter(ids: values.Cast<int>().ToArray());
                throw new InvalidOperationException();
            },
            // ...
        );
    }
    

 

When you call the ReloadRows method, the e.Take property returns int.Max. It allows the virtual source to refresh all rows you want to reload even if their number is greater than the number of rows you fetch at a time.

The code sample below fetches 30 rows at a time after a users scolls data.

static async Task<FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e) {
    // ...
    var take = e.Take ?? 30;
    var issues = await IssuesService.GetIssuesAsync(
        skip: e.Skip,
        take: take,
        sortOrder: sortOrder,
        filter: filter);
    // ...
}

If you select 50 rows and reload them, the virtual source will refresh all 50 rows.

((InfiniteAsyncSource)(grid.ItemsSource)).ReloadRows(selectedRowIds); 

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ReloadRows(Object[]) method.

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.

See Also