Skip to content

SetVirtualMode Method

Description

The SetVirtualMode method is used to enable virtual mode of the Grid Control.

Syntax

Public Sub SetVirtualMode( _
    ByVal [RowCount](#) As Integer, _
    Optional ByVal [FieldCount](#) As Integer = 0 _
)

Parameters

  • RowCount: Number of rows in the virtual grid.
  • FieldCount: (Optional) Number of fields in the virtual grid.

Remarks

VirtualMode should be used when there will be a very large number of rows in the Grid Control. VirtualMode can be used with any number of rows, but it is recommended that VirtualMode be used if adding more than 10,000 rows. Adding more than 10,000 rows in normal mode becomes quite slow. Using VirtualMode will dramatically increase performance.

VirtualMode does not require you to manually create the rows and records; all you need to do is fill in the record data in the BeforeDrawRow event when the record is being displayed.

When using VirtualMode, the rows that will be displayed should be stored internally in an array that can easily be accessed by the Grid Control.

The following steps should be followed when working in VirtualMode:

  1. Create your own array (dim) with the records that you want to show in the Grid Control. Each "row" in the array will represent a row in the Grid Control. Each element in the "row" of a multi-dimensional array will represent a record in a row.

  2. Call SetVirtualMode, specifying the number of rows that will be in the Grid Control.

  3. Call the SetCustomDraw method and specify that the xtpBeforeDrawRow event will be executed. By default, this event is not called.

  4. Use the BeforeDrawRow event to manually fill in the records for each row. Only records modified in the BeforeDrawRow event will become visible.

  5. Call Populate to adjust the scroll bars with the current virtual record count.

  6. Each time the number of rows increases or decreases, you must call VirtualMode #ofRows to indicate the new row count.

Note: You cannot group rows or use the tree view while in virtual mode.

Example

Virtual Mode Sample (Visual Basic)

This sample illustrates how to use Virtual Mode in the Grid Control.

' Index of columns  
Const ITEM_NUMBER = 0  
Const LIST_PRICE = 1  
Const SALE_PRICE = 2  
Const SAVINGS = 3  

' Records array to display in Grid control  
Dim OwnArray(1, 20000) As Long  

Private Sub Form_Load()  
    Dim Record As GridRecord  
    Dim i As Long  

    ' Randomly generates 20,000 records to display in the Virtual Grid  
    For i = 0 To 20000  
        ' Randomly generate List Price  
        OwnArray(0, i) = Rnd * 20000  
        ' Randomly generate Sale Price  
        OwnArray(1, i) = OwnArray(0, i) - Rnd * (OwnArray(0, i) / 2)  
    Next i  

    ' Adds 4 columns to the Grid control  
    wndGridControl.Columns.Add ITEM_NUMBER, "Item Number", 50, True  
    wndGridControl.Columns.Add LIST_PRICE, "List Price", 50, True  
    wndGridControl.Columns.Add SALE_PRICE, "Sale Price", 50, True  
    wndGridControl.Columns.Add SAVINGS, "Savings", 50, True  

    ' Tells the Grid control to use Virtual Mode and that there will be 20,000 rows  
    ' The row count must be updated when the row count changes.  
    wndGridControl.SetVirtualMode 20000  

    ' Adds a single "template" record to the Grid control. This template record is used  
    ' for all records in the Virtual Grid. The contents of each record are filled in during  
    ' the BeforeDrawRow event.  
    Set Record = wndGridControl.Records(0)  
    Record.AddItem ""  
    Record.AddItem ""  
    Record.AddItem ""  
    Record.AddItem ""  

    ' Updates the Grid  
    wndGridControl.Populate  

    ' Tells the Grid control to execute the BeforeDrawRow event,  
    ' By default, this event is not executed.  
    wndGridControl.SetCustomDraw xtpCustomBeforeDrawRow  
End Sub  

' When working in Virtual Mode, Row.Index should correspond to an element in the array that holds the  
' records to display in the Grid control.  
Private Sub wndGridControl_BeforeDrawRow(ByVal Row As IGridRow, _  
    ByVal Item As IGridRecordItem, ByVal Metrics As IGridRecordItemMetrics)  

    ' Determine which column the record is in  
    Select Case Item.Index  
        Case ITEM_NUMBER:  
            ' Displays data for the ITEM_NUMBER column  
            ' Displays the current row number, this corresponds to an element in OwnArray  
            Metrics.Text = "Item # " & Row.Index  
        Case LIST_PRICE:  
            ' Displays data for the LIST_PRICE column  
            Metrics.Text = "$ " & OwnArray(0, Row.Index)  
        Case SALE_PRICE:  
            ' Displays data for the SALE_PRICE column  
            Metrics.Text = "$ " & OwnArray(1, Row.Index)  
        Case SAVINGS:  
            ' Displays data for the SAVINGS column  
            Metrics.Text = "$ " & (OwnArray(0, Row.Index) - OwnArray(1, Row.Index))  
    End Select  
End Sub  

See Also


Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.