New to Telerik UI for WPF? Download free 30-day trial

Load items in the ItemsLoading event of VirtualQueryableCollectionView manually When Used in RadGridView

Environment

Product RadGridView for WPF
Version 2024.3.821

Description

How to manually load data in RadGridView using the VirtualQueryableCollectionView and its ItemsLoading event, without working with IQueryable collection source.

This approach is meaningful when you don't want to load all your data in-memory, but fetch it in the ItemsLoading event handler.

Solution

To do this, you can initialize the VirtualQueryableCollectionView with an empty collection source which later will be populated with data.

To adjust the total items count, set the VirtualItemCount property of the collection view.

In the ItemsLoading event handler, you can manually fetch and add items in the collection view.

Setting up the VirtualQueryableCollectionView

public MainWindow() 
{ 
    InitializeComponent(); 
 
    var vqcv = new VirtualQueryableCollectionView(new ObservableCollection<RowInfo>()) { LoadSize = 10, VirtualItemCount = 1000  };             
    vqcv.ItemsLoading += VirtualQueryableCollectionView_ItemsLoading;    
    this.gridView.ItemsSource = vqcv; 
} 
 
private void VirtualQueryableCollectionView_ItemsLoading(object? sender, VirtualQueryableCollectionViewItemsLoadingEventArgs e) 
{ 
    var vqcv = (VirtualQueryableCollectionView)sender; 
    var newItems = // fetch the new portion of items here 
    foreach (var item in newItems) 
    { 
        vqcv.Add(item); 
    } 
} 
In this article