Skip to content

Commit d97a579

Browse files
Merge pull request #2963 from telerik/new-kb-kb-virtualqueryablecollectionview-gridview-itemsloading-manuall-e7685f444f4c41dda6f25692ec5b74c9
Added new kb article kb-virtualqueryablecollectionview-gridview-itemsloading-manuall
2 parents 128deb0 + db7ec19 commit d97a579

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Load items in the ItemsLoading event of VirtualQueryableCollectionView manually When Used in RadGridView
3+
description: Handle the VirtualQueryableCollectionView.ItemsLoading event in RadGridView for WPF to load data on demand, suitable for large data sources.
4+
type: how-to
5+
page_title: How to Use VirtualQueryableCollectionView for On-Demand Data Loading in RadGridView
6+
slug: kb-virtualqueryablecollectionview-gridview-itemsloading-manuall
7+
tags: radgridview, wpf, virtualqueryablecollectionview, itemloading, on-demand data loading
8+
res_type: kb
9+
ticketid: 1666946
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadGridView for WPF</td>
19+
</tr>
20+
<tr>
21+
<td>Version</td>
22+
<td>2024.3.821</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
How to manually load data in `RadGridView` using the `VirtualQueryableCollectionView` and its `ItemsLoading` event, without working with `IQueryable` collection source.
30+
31+
This approach is meaningful when you don't want to load all your data in-memory, but fetch it in the `ItemsLoading` event handler.
32+
33+
## Solution
34+
35+
To do this, you can initialize the `VirtualQueryableCollectionView` with an empty collection source which later will be populated with data.
36+
37+
To adjust the total items count, set the `VirtualItemCount` property of the collection view.
38+
39+
In the `ItemsLoading` event handler, you can manually fetch and add items in the collection view.
40+
41+
#### __[C#] Setting up the VirtualQueryableCollectionView__
42+
{{region kb-virtualqueryablecollectionview-gridview-itemsloading-manuall-0}}
43+
public MainWindow()
44+
{
45+
InitializeComponent();
46+
47+
var vqcv = new VirtualQueryableCollectionView(new ObservableCollection<RowInfo>()) { LoadSize = 10, VirtualItemCount = 1000 };
48+
vqcv.ItemsLoading += VirtualQueryableCollectionView_ItemsLoading;
49+
this.gridView.ItemsSource = vqcv;
50+
}
51+
52+
private void VirtualQueryableCollectionView_ItemsLoading(object? sender, VirtualQueryableCollectionViewItemsLoadingEventArgs e)
53+
{
54+
var vqcv = (VirtualQueryableCollectionView)sender;
55+
var newItems = // fetch the new portion of items here
56+
foreach (var item in newItems)
57+
{
58+
vqcv.Add(item);
59+
}
60+
}
61+
{{endregion}}
62+
63+

0 commit comments

Comments
 (0)