Category / Section
What is a virtual grid in WinForms GridControl?
1 min read
Virtual grid
A Virtual Grid does not hold any data. All data is supplied to the Grid, from an external data source, on demand. When the Grid needs a particular cell, say to draw it, it asks the external data source for that value. Since no data is actually loaded into the Grid, there is virtually no limit imposed by Essential Grid on the number of rows and columns you can have.
C#
//Hook the below events in Form_Load to have a virtual grid gridControl1.QueryCellInfo += gridControl1_QueryCellInfo; gridControl1.QueryRowCount += gridControl1_QueryRowCount; gridControl1.QueryColCount += gridControl1_QueryColCount; private void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.ColIndex > 0 && e.RowIndex > 0) { e.Style.Text = string.Format("R{0}:C{1}", e.RowIndex, e.ColIndex); e.Handled = true; } } private void gridControl1_QueryRowCount(object sender, GridRowColCountEventArgs e) { //Set RowCount e.Count = 1000; e.Handled = true; } private void gridControl1_QueryColCount(object sender, GridRowColCountEventArgs e) { //Set ColCount e.Count = 100; e.Handled = true; }
VB
'Hook the below events in Form_Load to have a virtual grid gridControl1.QueryCellInfo += gridControl1_QueryCellInfo gridControl1.QueryRowCount += gridControl1_QueryRowCount gridControl1.QueryColCount += gridControl1_QueryColCount Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs) If e.ColIndex > 0 AndAlso e.RowIndex > 0 Then e.Style.Text = String.Format("R{0}:C{1}", e.RowIndex, e.ColIndex) e.Handled = True End If End Sub Private Sub gridControl1_QueryRowCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs) 'Set RowCount e.Count = 1000 e.Handled = True End Sub Private Sub gridControl1_QueryColCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs) 'Set ColCount e.Count = 100 e.Handled = True End Sub
The following screenshot displays the Virtual Grid.
Figure 1: Virtual Grid
Samples:
C#: VirtualGrid
VB:
VirtualGrid
Reference Link: https://help.syncfusion.com/windowsforms/grid-control/virtual-grid