corelibraries-devexpress-dot-data-dot-virtualservermodesource.md
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.
Namespace : DevExpress.Data
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
public event EventHandler<VirtualServerModeRowsEventArgs> ConfigurationChanged
Public Event ConfigurationChanged As EventHandler(Of VirtualServerModeRowsEventArgs)
The ConfigurationChanged event's data class is VirtualServerModeRowsEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CancellationToken | Gets a token that allows you to respond to a task cancellation request invoked by the grid control. |
| ConfigurationInfo | Gets information on the grid’s current sorting, filtering and summary configuration. |
| CurrentRowCount | Gets the count of rows currently loaded to the grid. |
| RowsTask | Gets or sets the task that returns requested rows. |
| UserData |
Read this parameter to get custom data passed from the previously called Task or ConfigurationChanged event handler. When handling the VirtualServerModeSource.ConfigurationChanged event, set the UserData event parameter to pass custom data to a subsequent VirtualServerModeSource.MoreRows event handler (unless you specify the RowsTask event parameter).
|
The ConfigurationChanged event fires in the following cases:
The ConfigurationChanged event allows you prepare your data for the load in the grid control, and optionally provide an initial batch of rows. To provide a batch of rows, create a Task that will return requested rows, and assign this task to the RowTask event parameter. To provide subsequent batches of rows (when required), handle the VirtualServerModeSource.MoreRows event.
You can provide an initial and subsequent batches of rows by handling a single event - VirtualServerModeSource.MoreRows. In this case, if you handle the ConfigurationChanged event, leave the event’s RowTask parameter set to null.
Tip
A Task typically executes asynchronously. To return a batch of rows synchronously, create the task with the Task.FromResult method (available in .NET Framework 4.5+).
This example demonstrates how to create a WinForms Grid Control and bind it to a virtual server mode source.
using System.Windows.Forms;
using System.Collections.Generic;
using DevExpress.Data;
using DevExpress.XtraGrid;
using DevExpress.XtraEditors;
namespace DXApplication {
public partial class Form1 : XtraForm {
public Form1() {
InitializeComponent();
// Creates and initializes a virtual data source.
VirtualServerModeSource virtualServerModeSource = new VirtualServerModeSource();
virtualServerModeSource.RowType = typeof(Product);
virtualServerModeSource.ConfigurationChanged += virtualServerModeSource_ConfigurationChanged;
virtualServerModeSource.MoreRows += virtualServerModeSource_MoreRows;
// Creates a grid control and binds it to the virtual data source.
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 System.Windows.Forms
Imports System.Collections.Generic
Imports DevExpress.Data
Imports DevExpress.XtraGrid
Imports DevExpress.XtraEditors
Namespace DXApplication
Public Partial Class Form1 Inherits XtraForm
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
See Also