Home > Language Reference > Classes > GridEx

AddItem Method

Adds an item to a grid control.

Syntax

Public Sub AddItem(ByVal lItemData As Long, Optional ByVal bMasked As Boolean = False, Optional ByVal iIndex As Integer = 32767)

ParameterDescription
lItemDataItem value.
iIndexRow index (optional).
bMaskedInitial value for the Masked property (optional)

Remarks

The AddItem method adds a row to the grid control. The lItemData parameter specifies the programmer's defined value by which this item will be referenced later. The iIndex parameter specifies where the new item should be inserted; if omitted, the item will be appended at the end of the list. The bMasked parameter specifies an optional initial value for the Masked property.

By default, the control is redrawn on each insertion. If you are inserting several elements consecutively, it is advised to temporarily set the Redraw property to False, in order to improve performances and prevent the control from flickering.

You should keep in mind that the grid control only stores the lItemData value for each item. The values to be displayed in each column are not stored, but claimed on the fly by raising a LoadItem event (and possibly a DrawItem event) each time the control needs to redraw itself. Therefore, you should always provide an event handler for those events before your grid control can display the items you add using this method. The following example illustrates that:

Private Sub Form_Load()
  Dim i As Integer

  Grid1.Redraw=False
  For i=0 to 99
    Grid1.AddItem i
  Next i
  Grid1.Redraw=True
End Sub

Private Sub Grid1_LoadItem(ByVal iRow As Integer, ByVal lItemData As Long, ByVal vValue() As Variant)
  vValue(0)="item " & lItemData
End Sub

In this example, the GridEx control should contain a single column whose type has been set to 'Label'.

Note that you can also change the number of items in a grid control by affecting a new value to the Rows property.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0-
Windows CEWindows CE 3.0-