Help Center

Recordsetproperty

Used to bind hierarchical or flat ADO data to the grid.

Windowspropertydoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Syntax

PROPERTY Recordset () AS Afx_ADORecordsetPTR
PROPERTY Recordset (BYVAL rs AS Afx_ADORecordset PTR)

Parameters

NameDescription
rsA reference to an ADO Recordset.

Description

Returns or sets the recordset. Used to bind hierarchical or flat ADO data to the grid.

Remarks

You can bind it to a live recordset at runtime using the following syntax:

While the grid usually references the data through the DataSource property, it maintains an internal reference to the underlying Recordset for hierarchical navigation and data retrieval.

The MSHFlexGrid is uniquely designed to display "shaped" recordsets. If your recordset has a parent-child relationship (created via the MSDataShape provider), the grid automatically creates collapsible bands.

Even when bound to a recordset, the MSHFlexGrid is read-only by default. Users cannot type into cells to update the recordset; you must use an overlay (like a TextBox) to capture changes and manually update the recordset fields.

A long-standing legacy limitation is that the MSHFlexGrid may only display the first 2,048 rows when bound to a recordset, even if more records exist. To display more than this, developers use the GetString method of the recordset combined with the grid's Clip property for a manual, high-speed population.

When binding a recordset, ensure proper cursor and lock settings to prevent runtime errors:

Cursor type: Use adOpenStatic or adOpenKeyset to ensure the recordset supports counting and navigation.

Lock type: Use adLockReadOnly for simple displays, or adLockOptimistic if you intend to perform manual updates to the data through code.

Refreshing data: To reflect changes made to the recordset (such as a deleted row), you can re-set the DataSource property to force the grid to rebuild its view.

Note that in some specific environments or versions, attempting to set grid.Recordset = rs directly may result in a "Type Mismatch" error. It is generally safer and more reliable to use grid.DataSource = rs.DataSource for runtime binding.

Many developers prefer using the grid in unbound mode to avoid binding limitations. You can manually manipulate the data rows using:

AddItem: Appends a new row to the grid.

TextMatrix(row, col): Directly sets or retrieves the text of any specific cell without changing the selection focus.

Examples

' Assuming "rs" is an open ADODB Recordset grid.Recordset = rs

' Assuming "rs" is an open ADODB Recordset grid.DataSource = rs.DataSource

Reference