Articles in this section
Category / Section

How to implement a minimal virtual grid in WinForms GridControl?

1 min read

Virtual grid

There are three steps that you have to follow in order to implement a read-only in WinForms 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 in WinForms Grid

Figure 1: Virtual grid

Samples:

C#: MinimalVirtualGrid

VB: MinimalVirtualGrid

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied