Bound Mode > Binding True DBGrid to a Data Source > Binding to an OLE DB data source |
To associate a True DBGrid control (TODG8.OCX) with an OLE DB data source, set the DataSource property of the grid to the name of an available data source. If necessary, set the DataMember property to the name of a table or query exposed by the data source. At design time, these properties can only be set in the Visual Basic Properties window.
Unlike the legacy control (TDBG8.OCX), the OLE DB version of True DBGrid supports assignment to the DataSource property at run time. The following code sample demonstrates how to bind the grid to a Data Environment command:
Example Title |
Copy Code
|
---|---|
With TDBGrid1
Set .DataSource = DataEnvironment1
.DataMember = "Command1"
End With
|
The most widely used form of binding a grid to a data source at run time is to assign an ADO recordset to the DataSource property:
Example Title |
Copy Code
|
---|---|
Dim RS As New ADODB.Recordset RS.Open ... TDBGrid1.DataSource = RS |
Note: If you are binding True DBGrid to an ADO recordset in an HTML page, you may need to set the BookmarkType property before passing grid bookmarks to its data source. For more information, see the documentation for the BookmarkType property and DataSourceChanged event.