Home > Language Reference > Classes

GridEx Class

  + Object
    + Display
      + UIComponent
        + Control
          + GridEx

Description

The GridEx class implements the behaviours specific to grid controls. Like all classes derived from UIComponent, this class is not instantiable, cloneable or derivable. The only instances available to the programmer are those automatically generated by HB++ when you place the corresponding control on a form.

The GridEx control allows you display and edit data in a tabular form. It is very similar to the previously existing Grid control, but provides both vertical and horizontal scrolling, extended selection modes (free, by rows, or by cells), resizeable columns, and compatibility with the new Dynamic Input Area feature. On the other hand, this new control does not provide in-place editing of text yet. When possible, it is advised you use this control instead of the old Grid control.

Unlike other controls, GridEx controls do not store the data to be displayed directly, but only a single, Long value for each row, called ItemData. When the control needs to display a given row, the data to be displayed in each column are claimed on-the-fly by raising a LoadItem event; it is then up to your code to provide the requested data. The following example schematically shows how to fill and display a grid control with data from a table:

Private db As New tblMyDatabase ' Replace this by the name of your table

Private Sub Form_Load()
  db.OpenTable hbModeOpenExisting+hbModeReadOnly
  Grid1.Populate db
End Sub

Private Sub Form_Unload()
  db.Close
End Sub

Private Sub Grid1_LoadItem(ByVal iRow As Integer, ByVal lItemData As Long, ByVal vValue() As Variant)
  db.LookupUniqueID lItemData
  
  vValue(0) = db.SomeTextField     ' Replace this by the name of field to display in the first column
  vValue(1) = db.AnotherTextField  ' Replace this by the name of field to display in the second column
End Sub

An internal caching mechanism avoids your code receive to many LoadItem events, which would impact performances.

The type of each column in a grid is determined at design time by the Columns property. The following table summarizes the various types of columns the grid control supports; please refer to this property for detailed information:

Column TypeDescription
Label The cells of this column are labels. They display text, but cannot be edited.
CheckboxThe cells of this column are checkboxes, and support in place editing.
PopupThe cells of this column are of popup lists, and support in place editing.
User drawThe cells of this column are user drawn. The control raises a DrawItem event each time it needs those cells to be repainted.

There are two ways to specify the number of rows in the Grid object; either by using the Rows property or by adding rows one by one with the AddItem method which also allows to specify for each line added an associated value in the ItemData property and an initial value for the Masked property. When you use the GridEx class to display the contents of a database, it is convenient to store in the ItemData property the unique identifier associated with each record in a database.

Whichever method is used to set the number of rows in the Grid object, the Rows property returns the number of items in the Grid object.

The Click event is raised when the user clicks on the GridEx control. If the clicked cell is editable, it enters in edit mode; as soon as the user is done, the control reverts to standard mode, and a Change event is raised. The various parameters passed along with this event allows to determine which cell was edited and the new value the user entered.

The SelectionMode property lets you choose the selection mode: free, by rows, or by column. This mode can be changed at any time. Note however that cells cannot be edited if the SelectionMode is not set to hbSelectCell. You can also programmatically select and highlight a given cell using the SelectItem method.

Members

MembersDescription
AddItem Adds an item to a grid control.
Change Event raised when a cell is edited.
Clear Deletes all the items in a grid.
Click Event raised when a cell is clicked.
Col Column index of the currently selected cell.
Cols Number of columns in the grid control.
ColumnHeight Height of the cells of a given column.
ColumnType Type of a given column.
ColumnWidth Width of a given column.
DrawItem Event raised each time a user draw cell has to be repainted.
EnsureVisible Ensures that an element is visible by scrolling - if necessary - the contents of the grid.
FindItemData Finds an item in a grid from its value.
HorzScroll Horizontal scrollbar attached to the grid.
ItemData User value associated with a row.
LeftCol Index of the first displayed column.
List Reference to the List object associated to a grid column.
LoadItem Event raised to fetch new data into the grid control.
Masked Indicates whether a row contains secret data or not.
Populate Fills the grid control with the content of a Recordset.
Redraw Determines whether the control is updated each time its content is altered.
ReloadItem Reloads the data associated with one or several rows.
RemoveItem Removes a row from the grid control.
Row Row index of the currently selected cell.
Rows Number of rows in the grid control.
SelectionMode Defines the selection mode.
SelectItem Selects and highlights the specified item.
TopItem Index of the first displayed row.
VertScroll Vertical scrollbar attached to the grid.
VisibleRows Number of visible rows.
Inherited from ControlDescription
DrawFocusRing Draws the focus ring.
GotFocus Event raised when the control gains the focus.
Layer Layer to which the control belongs.
LostFocus Event raised when the control loses the focus.
NavFlags Navigation flags for the control.
RemoveFocusRing Erase the focus ring.
Tag String associated with the control.
Visible Indicates if a control is visible or not.
Inherited from UIComponentDescription
ComponentToScreen Converts coordinates relative to a component into coordinates relative to the screen.
FiveWayNavigator Event raised when the user presses one of the 5-way navigator keys.
Height Element height.
Left Distance between the left edge of the form and the left edge of the element.
Move Moves or resizes an element.
PenDown Event raised when the user touches an UI element with the stylus.
PenMove Event raised when the user moves the stylus.
PenUp Event raised when the user releases the stylus.
ScreenToComponent Converts coordinates relative to the screen into coordinates relative a component.
Top Distance between the top edge of the form and the top edge of the element.
UIRef Internal reference to a control.
Width Element width.
Inherited from DisplayDescription
Arc Draws an arc.
BackColor Background color.
BatchLimit Size of the graphics instruction buffer.
CoordinateSystem Coordinates system.
CopyArea Efficiently copies part of a Display object to another.
DrawFont Font used to draw the text.
Flush Empties the graphics instruction buffer.
FontMetrics Returns a FontMetrics object describing the physical charateristics of the currently active font.
ForeColor Foreground color.
GetPixel Queries the color of a given pixel.
hWin Returns the window handle.
Line Draws a line.
Oval Draws a circle or ellipse.
Pattern Defines the pattern used to fill drawings.
Polygon Draws a polygon.
PutPixel Sets the color of a pixel.
Rectangle Draw a rectangle.
ResID Identifier of the resource associated with the object.
ScaleFont Enable or disable font scaling.
TextColor Text color.
TextOut Draw text.
Inherited from ObjectDescription
ClassID Returns the type identifier corresponding to the actual class of the object.
Implements Determines whether the object implements the features of a given class.
Iterate Event raised to iterate over the elements of a container object.
Recipient Recipient of events sent by the object.
Serialize Event raised to serialize the object content into a stream.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A