)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to implement a minimal virtual grid in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 20, 2019

Virtual grid

There are three steps that you have to follow in order to implement a read-only virtual grid. In the QueryCellInfo, provide the actual data from your external data source. In the QueryRowCount, provide the number of rows that are in the virtual grid, and in the QueryColCount, provide the number of columns in the virtual grid.

C#

//Hook the Events in Form_Load.
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_QueryColCount(object sender, GridRowColCountEventArgs e)
{
    e.Count = 100;
    e.Handled = true;
}
private void gridControl1_QueryRowCount(object sender, GridRowColCountEventArgs e)
{
    e.Count = 1000;
    e.Handled = true;
}

VB

'Hook the Events in Form_Load.
Private gridControl1.QueryCellInfo += AddressOf gridControl1_QueryCellInfo
Private gridControl1.QueryRowCount += AddressOf gridControl1_QueryRowCount
Private gridControl1.QueryColCount += AddressOf 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_QueryColCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs)
    e.Count = 100
    e.Handled = True
End Sub
Private Sub gridControl1_QueryRowCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs)
    e.Count = 1000
    e.Handled = True
End Sub

 

Note:

For changing the value of the cell, add the SaveCellInfo event.

 Displaying virtual grid

Figure 1: Virtual grid

Samples:

C#: MinimalVirtualGrid

VB: MinimalVirtualGrid

Reference link: https://help.syncfusion.com/windowsforms/grid-control/virtual-grid

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon