This documentation is archived and is not being maintained.

Visual Basic: DataGrid Control

Visual Studio 6.0

DataGrid Control

See Also   Example   Properties   Methods   Events

Displays and enables data manipulation of a series of rows and columns representing records and fields from a Recordset object.

Syntax

DataGrid

Remarks

The data-aware DataGrid control appears similar to the Grid control; however, you can set the DataGrid control's DataSource property to a Data control so that the control is automatically filled and its column headers set automatically from a Data control's Recordset object. The DataGrid control is really a fixed collection of columns, each with an indeterminate number of rows.

Each cell of a DataGrid control can hold text values, but not linked or embedded objects. You can specify the current cell in code, or the user can change it at run time using the mouse or the arrow keys. Cells can be edited interactively, by typing into the cell, or programmatically. Cells can be selected individually or by row.

If a cell's text is too long to be displayed in the cell, the text wraps to the next line within the same cell. To display the wrapped text, you must increase the cell's Column object's Width property and/or the DataGrid control's RowHeight property. At design time, you can change the column width interactively by resizing the column or by changing the column's width in the Column object's property page.

Use the DataGrid control's Columns collection's Count property and the Recordset object's RecordCount property to determine the number of columns and rows in the control. A DataGrid control can have as many rows as the system resources can support and up to 32767 columns.

When you select a cell, the ColIndex property is set, thus selecting one of the Column objects in the DataGrid object's Columns collection. The Text and Value properties of the Column object reference the contents of the current cell. The data in the current row can be accessed using the Bookmark property, which provides access to the underlying Recordset object's record. Each column of the DataGrid control has its own font, border, word wrap, and other attributes that can be set without regard to other columns. At design time, you can set the column width and row height and establish columns that are not visible to the user. You can also prevent users from changing the formatting at run time.

Note   If you set any of the DataGrid column properties at design time, you will need to set all of them in order to maintain the current settings.

Note   If you use the Move method to position the DataGrid control, you may need to use the Refresh method to force it to repaint.

The DataGrid control functions similarly to the DBGrid control except that it doesn't support an unbound mode.

Note   This control is Unicode-enabled. When used on a Unicode-enabled system such as Microsoft Windows NT, the control passes Unicode data with no conversion. On other systems, however, data is converted from ANSI to Unicode and back. For more information, see "ANSI, DBCS, and Unicode: Definitions" in the Programmer's Guide.

Show: