corelibraries-devexpress-dot-data.md
A data source that features event-based data operations: async data load, sorting, filtering and infinite scrolling through records (in a bound Windows Forms GridControl).
Namespace : DevExpress.Data
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.VirtualServerModeSource.bmp")]
public class VirtualServerModeSource :
Component,
IListSource,
ISupportInitialize
<ToolboxBitmap(GetType(ResFinder), "Bitmaps256.VirtualServerModeSource.bmp")>
Public Class VirtualServerModeSource
Inherits Component
Implements IListSource,
ISupportInitialize
The VirtualServerModeSource is an event-based data source for the DevExpress WinForms Data Grid. The data source exposes events that allow you to asynchronously load data in batches and take into account the grid’s sort and filter configuration.
A Data Grid bound to VirtualServerModeSource supports infinite scrolling. On startup, the Data Grid fetches an initial batch of records from the data source. The Data Grid does not know the total number of records in the data source. Its scroll bar always reflects the current number of loaded rows. Once a user scrolls to the last loaded record, the Data Grid requests an additional batch of records and adjusts its scroll bar to match the new loaded record count.
Run Demo: Infinite Scrolling Tutorial
Note
The Data Grid does not support Data Grouping if it is bound to VirtualServerModeSource.
The VirtualServerModeSource exposes the following main events:
Fires on initial data load and reload in the bound grid control, and when the data grid’s sort and filter configuration changes. Allows you to initialize the data source and (optionally) return an initial batch of records.
using DevExpress.Data;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraGrid;
using System.Collections.Generic;
using System.Windows.Forms;
namespace DXApplication {
public partial class Form1 : RibbonForm {
public Form1() {
InitializeComponent();
VirtualServerModeSource virtualServerModeSource = new VirtualServerModeSource();
virtualServerModeSource.RowType = typeof(Product);
virtualServerModeSource.ConfigurationChanged += virtualServerModeSource_ConfigurationChanged;
virtualServerModeSource.MoreRows += virtualServerModeSource_MoreRows;
GridControl gridControl = new GridControl();
gridControl.Parent = this;
gridControl.Dock = DockStyle.Fill;
gridControl.DataSource = virtualServerModeSource;
}
int batchSize = 20;
int maxRowCount = 500;
private void virtualServerModeSource_ConfigurationChanged(object sender, DevExpress.Data.VirtualServerModeRowsEventArgs e) {
e.UserData = GetRows(0);
}
private void virtualServerModeSource_MoreRows(object sender, DevExpress.Data.VirtualServerModeRowsEventArgs e) {
e.RowsTask = System.Threading.Tasks.Task.Factory.StartNew(() => {
bool moreRows = e.CurrentRowCount < maxRowCount - batchSize;
return new VirtualServerModeRowsTaskResult(GetRows(e.CurrentRowCount), moreRows, e.UserData);
}, e.CancellationToken);
}
List<Product> GetRows(int startRowIndex) {
List<Product> lst = new List<Product>();
for (int i = startRowIndex; i < startRowIndex + batchSize; i++)
lst.Add(new Product { ID = i, Name = $"Product{i}" });
return lst;
}
}
public class Product {
public int ID { get; set; }
public string Name { get; set; }
}
}
Imports DevExpress.Data
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraGrid
Imports System.Collections.Generic
Imports System.Windows.Forms
Namespace DXApplication
Public Partial Class Form1 Inherits RibbonForm
Public Sub New()
InitializeComponent()
Dim virtualServerModeSource As VirtualServerModeSource = New VirtualServerModeSource()
virtualServerModeSource.RowType = GetType(Product)
AddHandler virtualServerModeSource.ConfigurationChanged, AddressOf virtualServerModeSource_ConfigurationChanged
AddHandler virtualServerModeSource.MoreRows, AddressOf virtualServerModeSource_MoreRows
Dim gridControl As GridControl = New GridControl()
gridControl.Parent = Me
gridControl.Dock = DockStyle.Fill
gridControl.DataSource = virtualServerModeSource
End Sub
Private batchSize As Integer = 20
Private maxRowCount As Integer = 500
Private Sub virtualServerModeSource_ConfigurationChanged(ByVal sender As Object, ByVal e As VirtualServerModeRowsEventArgs)
e.UserData = GetRows(0)
End Sub
Private Sub virtualServerModeSource_MoreRows(ByVal sender As Object, ByVal e As VirtualServerModeRowsEventArgs)
e.RowsTask = System.Threading.Tasks.Task.Factory.StartNew(Function()
Dim moreRows = e.CurrentRowCount < maxRowCount - batchSize
Return New VirtualServerModeRowsTaskResult(GetRows(e.CurrentRowCount), moreRows, e.UserData)
End Function, e.CancellationToken)
End Sub
Private Function GetRows(ByVal startRowIndex As Integer) As List(Of Product)
Dim lst As List(Of Product) = New List(Of Product)()
For i = startRowIndex To startRowIndex + batchSize - 1
lst.Add(New Product With {
.ID = i,
.Name = $"Product{i}"
})
Next
Return lst
End Function
End Class
Public Class Product
Public Property ID As Integer
Public Property Name As String
End Class
End Namespace
The following events allow you to control data shaping operations invoked in the bound Data Grid control and enable CRUD operations:
This event can be handled to provide an inner list that will be storage for rows fetched using the VirtualServerModeSource’s events. To enable CRUD operations in a bound Data Grid, you need to provide an inner list that supports these operations. If no inner list is supplied (or you do not handle the AcquireInnerList event), CRUD operations are disabled in the grid control.
Specify the VirtualServerModeSource.RowType property at design time to populate the bound grid control with columns.
If the RowType property is not specified, handle the AcquireInnerList event to manually supply a list that will store rows fetched by VirtualServerModeSource’s events.
Object MarshalByRefObject Component VirtualServerModeSource
See Also