Data-aware grids to display and operate on information in a database

dbgrids.pas contains classes and types needed to implement a database-aware grid control.

Exception raised for an invalid grid operation

EInvalidGridOperation is an Exception class raised when an invalid grid operations is performed.

TBookmarkList.CheckActive
Specifies an event handler signalled after scrolling a dataset

TDatasetScrolledEvent specifies an event handler signalled after scrolling a dataset.TDatasetScrolledEvent can be used to perform actions required when the position in the DataSet has changed.

DataSet is the TDataset instance for the event notification.

Distance indicates both the number of rows and the direction for the event notification, for example:

Value
Meaning
<0
Scroll toward the beginning of the DataSet
0
Current row in the DataSet has been refreshed
>0
Scroll toward the end of the DataSet

TDatasetScrolledEvent is the type used for the OnDataSetScrolled property in TComponentDataLink.

See the TCustomDBGrid.OnDataSetScrolled procedure for an example implementation of TDatasetScrolledEvent.

Dataset for the event Number of rows and direction for the event Event handler signalled to coordinate Field selection and control focus

TFocusControlEvent specifies an event handler signalled to coordinate Field selection and control focus.

TComponentDataLink.OnFocusControl TCustomDBGrid.OnFocusControl
Field reference for the focus event Specifies an event handler signalled when a grid column in is clicked

TDBGridClickEvent specifies an event handler signalled when a column in the database grid is clicked

Column for the event Specifies an event handler signalled when the display order of rows or columns is changed

TMovedEvent specifies an event handler signalled when the display order of rows or columns is changed. TMovedEvent is the type used for the OnColumnMoved and OnRowMoved properties in TDBGrid.

Grid control for the event Previous ordinal position for the event New ordinal position for the event Specifies an event handler for drawing a cell in a grid control

TDrawColumnCellEvent specifies an event handler used to draw a cell in a column for a grid control. TDrawColumnCellEvent is the type used for the OnDrawColumnCell property in TDBGrid, and signalled from its DrawCell method.

Grid control for the event` Canvas rectangle where the cell is drawn Position of the Field used to get data for the event Column definition for the event` Drawing state for the event Specifies an event handler used to get the Edit Mask for a cell in a grid

TGetDbEditMaskEvent specifies an event handler used to get the Edit Mask for a cell in a database grid control. TGetDbEditMaskEvent can be used to provide an edit mask for the specified Field. TGetDbEditMaskEvent is the type used for the OnFieldEditMask property in TDBGrid.

TCustomDBGrid.OnFieldEditMask
Grid control for the event Field for the event Default value for the edit mask Enumerated type containing options available for a database grid

TDBGridOption is an enumerated type containing options available for a database grid control. Each enumeration value indicates if the associated feature or behavior is enabled in a database grid control.

Values from the enumeration are stored in the TDBGridOptions set type, and are used in the TDBGrid.Options property.

TDBGridOptions TDBGrid.Options
Indicates cells in the grid can be edited Indicates titles are displayed for columns in the grid Enables drawing of the row indicator for the currently selected row in the grid Indicates columns in the grid can be resized Indicates the order of columns in the grid can be changed Indicates vertical lines are drawn between columns in the grid Indicates horizontal lines are drawn between rows in the grid Indicates the Tab key can be used to navigate between cells in the grid Indicates an edit control is always displayed for the current cell in the grid Indicates the entire row is highlighted when selected Indicates the current selection is displayed even when the control loses focus Indicates a confirmation dialog is required when deleting a record in the grid Indicates an active editing operation is cancelled when the control loses focus Indicates more than one cell or row can be selected in the grid Indicates column headers are highlighted when the column has mouse focus Indicates column headers are drawn with a button down appearance Indicates multiple selections are retained even when the control loses focus Indicates columns are automatically resized to fit their content Indicates that any mouse button can change the selection in the grid Indicates if deleting records with Ctrl + Delete is disabled Indicates if inserting (or appending) records is disabled Indicates if displaying a hint for an individual cell is enabled Indicates if cell hints are truncated when they are too long Indicates if an Ellipsis character is added to the end of cells longer than the display area for the cell Indicates if the current row in the grid is highlighted instead of the current cell Indicates if the current selection is changed when the mouse thumb wheel is scrolled Indicates if double clicking on borders or headers for a column causes it to be automatically resized to its contents Indicates if memo content is displayed instead of the '(Memo)' string literal for ftMemo Fields Enumerated type that specifies extra options available in a database grid

TDbGridExtraOption is an enumerated type that specifies extra options available in a database grid. Values from TDbGridExtraOption are stored in the TDbGridExtraOptions set type, and used in the TDBGrid.OptionsExtra property.

TDBGrid.OptionsExtra
Indicates if Fields in the dataset are automatically added as columns in the database grid Indicates that checkbox controls are used to edit Boolean Fields in the grid dataset TDbGridExtraOptions is a set of values from the TDbGridExtraOption enumeration Stores values from the TDbGridOption enumeration TDbGridOptions is a set type used to store values from the TDbGridOption enumeration. TDbGridOptions is the type used for the TDBGrid.Options property. TDBGridOption TDBGrid.Options Enumerated type with values for status messages in a database grid

TDbGridStatusItem is an enumerated type with values for status messages used in a database grid. Values from TDbGridStatusItem are stored in TDbGridStatus, and used in the TDBGrid.GridStatus property.

TDbGridStatus TDBGrid.GridStatus
Indicates the grid is updating after a change in data Indicates automatic columns are being added for the grid control Indicates automatic columns are being removed from the grid control Indicates automatically sized columns are currently in use in the grid control Indicates the data link for a grid control is updating the value in its Editing property Indicates the grid control is loading its settings from a file or stream Set type used to store TDbGridStatusItem enumeration values

TDbGridStatus is a set type used to store TDbGridStatusItem enumeration values. Values added to TDbGridStatus indicate that a feature or behavior has been enabled in a TDBGrid control.

TDbGridStatus is used to implement the TDBGrid.GridStatus property.

TDbGridStatusItem TDBGrid.GridStatus
Specifies an event handler used to select a cell editor in a database grid

TDbGridSelEditorEvent specifies an event handler used to select an editor for a cell in a database grid.

TDBGrid.OnSelectEditor TDBGrid.SelectEditor
Control signalling the event Column for the control Editor for the specified column Specifies an event handler which prepares the canvas for drawing a database grid

TPrepareDbGridCanvasEvent specifies an event handler used to prepare the canvas which draws the content in a database grid. TPrepareDbGridCanvasEvent allows an application to override or enhance the drawing behavior of cells in a database grid.

TPrepareDbGridCanvasEvent is used to implement the OnPrepareCanvas event handler in TDBGrid.

TDBGrid.OnPrepareCanvas
Control signalling the event Drawing state for the selection Enumeration with option values for the bookmarked record enumerator

TBookmarkedRecordEnumeratorOptions is a set type with option values that control the actions performed in TBookmarkedRecordEnumerator. TBookmarkedRecordEnumeratorOptions is the type used to implement the TBookmarkedRecordEnumerator.Options property.

TBookmarkedRecordEnumerator
Disables controls attached to the dataset Stops enumerating when an invalid bookmark is encountered Restores the current bookmark when exiting the enumerator Defines a bookmarked record enumeration class

TBookmarkedRecordEnumerator is a Class which defines a bookmarked record enumerator for use in TBookmarklist.

TBookmarkList
Constructor for the class instance

Create is the constructor for the class instance. Create calls the inherited constructor, and stores the arguments to the method in its BookmarkList, Dataset, and Options properties.

Bookmark list for the enumerator Grid control for the enumerator Options for the enumerator Destructor for the class instance

Destroy is the destructor for the class instance. Destroy uses values in the Options property to perform actions needed before the class instance is freed, including:

  • Restore the dataset to the position in Bookmark
  • Re-enable controls attached to the dataset if disabled

Destroy calls the inherited destructor before exit.

Moves to the next bookmark in the list

MoveNext is a Boolean function used to move the enumerator to the next item in the bookmark list. Move next increments the value in BookmarkIndex, and examines the Options property to see if any actions are required, such as: setting the value of the Current Bookmark before navigation, or disabling controls attached to the dataset.

MoveNext updates the current bookmark and checks the dataset to see if the bookmark is still valid. The return value is False if the record for the bookmark no longer exists in the dataset and Options indicates the enumerator should halt for an invalid bookmark. False is also returned when the value in BookmarkIndex exceeds the number of items in the BookmarkList.

The return value is True when the action has been performed successfully.

True when the action has been performed successfully Returns the current class instance

GetEnumerator is a TBookmarkedRecordEnumerator function used to the current class instance.

The current class instance Current bookmark for the enumerator

Current is a read-only TBookmark property which returns the current bookmark for the enumerator. The value in Current in updated when the MoveNext method is called.

Controls the actions performed when Bookmarks are visited

Options is a TBookmarkedRecordEnumeratorOptions property which controls the actions performed when Bookmarks in the enumerator are visited. Values are included in the set type to enable the corresponding feature in the enumerator.

See TBookmarkedRecordEnumeratorOptions for more information about option values and their meanings.

TBookmarkList implements a list of Bookmarks in a database grid

TBookmarkList is a class used to implement a list of Bookmarks in a database grid. TBookmarkList is the type used for the SelectedRows property in TDBGrid.

TDBGrid.SelectedRows
Gets the value for the Count property GetCount is an Integer function that implements the read access specifier for the Count property. Use the Items property to access TBookmark instances stored in the list. Number of bookmarks in the list Gets the value in the for the CurrentRowSelected property

GetCurrentRowSelected is a Boolean function that implements the read access specifier for the CurrentRowSelected property. GetCurrentRowSelected calls the CheckActive method to ensure that the Dataset for the list is properly configured. See CheckActive for more information.

The return value is True when a TBookmark instance for the current row already exists in the list.

True when a bookmark for the current row already exists in the list Gets the value for the bookmark stored at the specified position in the list

GetItem is a TBookmark function that implements the read access specifier for the Items property. GetItems returns the bookmark stored at the specified ordinal position in the list. AIndex is the ordinal position to retrieve in the range 0 .. Count - 1. Use the Items property to access the bookmarks stored in the list.

The bookmark at the specified position Sets the value in the CurrentRowSelected property

SetCurrentRowSelected is a procedure which provides write access for the CurrentRowSelected property. SetCurrentRowSelected gets a bookmark for the current row, and calls Find to determine if the bookmark already exists in the list. When AValue contains False, an existing bookmark is freed and removed from the bookmark list. A Bookmark not in the list is created and added when AValue is True.

True to select the current row. False to de-selected the current row Ensures that the dataset for the bookmark list is properly configure and active

CheckActive is a procedure used to ensure that the bookmark list is active and properly configured. CheckActive examines the DataLink for the Grid to determine if it is active. An EInvalidGridOperation exception is raised if the dataset is not already active.

CheckActive compares the datasets in the bookmark list and the associated Grid control. If they are the same Dataset, no additional processing is performed in the method. Otherwise, the Dataset for the bookmark list is set to the Dataset from the associated Grid control.

EInvalidGridOperation
Raised when the DataLink in the Grid control has an inactive Dataset; exception message is 'Dataset Inactive'.
Create is the constructor for TBookmarkList

Create is the constructor for the TBookmarkList class instance. Create calls the inherited constructor. Create stores the AGrid argument internally to keep an association to the grid for the Bookmarks. Finally, Create initializes the internal list used to store Bookmarks added to the class instance.

TObject.Create
Grid control that owns the bookmark list Destroy is the destructor for TBookmarkList

Destroy is an overridden destructor for the TBookmarkList class instance. Destroy ensures that TBookmark items are removed from the list and freed before the list is freed. Destroy calls the inherited destructor.

TBookmark
Clear removes all Items in the bookmark list

Clear is a procedure used to remove all of the Items stored in the list. Clear calls the TDataset.FreeBookmark method for each of the TBookmark instances in Items. The length of the Bookmark is set to 0 to decrease the reference count for the memory allocation.

Clear uses the Invalidate method in the associated Grid control to force it to be redrawn.

Deletes rows in the Dataset represented by bookmarks in the list

Delete is a procedure used to delete rows in the Dataset represented by bookmarks in the list. Delete processes the Items in the list in reverse order. Each bookmark is located in the Dataset and the TDataset.Delete method is called to remove the data from the dataset. The Dataset.FreeBookmark method is called to free the Bookmark, and it is removed from the Items in the list.

Find locates the specified Bookmark and its position in the list

Find is a Boolean function used to locate the specified bookmark in the Items for the bookmark list. AIndex contains the position in the list where the bookmark was located. The return value is True when the specified bookmark is located in the bookmark list.

True when the bookmark is located in the list Bookmark to locate Position in the list for the bookmark IndexOf returns the ordinal position for the specified Bookmark in the list

IndexOf is an Integer function used to get the ordinal position in the list for the specified Bookmark. The return value contains the position in the list where the TBookmark instance was located. IndexOf calls Find to locate the bookmark and to capture the return value for the method. The return value is in the range 0..Count-1 when the bookmark exists in the list or -1 when the bookmark is not found.

Position in the list for the bookmark Bookmark to find in the list Searches for and removes invalid Bookmarks in the list

Refresh searches for and removes invalid Bookmarks in the list; returns True if the action was successful.

True when the refresh action was successful Indicates the number of Bookmarks in the list

Count is a read-only Integer property that indicates the number of Bookmarks in the list. GetCount is the read access specifier for the property value.

Indicates if the current row in the Dataset is selected

CurrentRowSelected is a Boolean property that indicates if the current row in the Dataset is selected.

GetCurrentRowSelected is the read access specifier for the property value. GetCurrentRowSelected checks to see if the Bookmark for the current row exists in BookmarkList.

SetCurrentRowSelected is the write access specifier for the property value. SetCurrentRowSelected tries to locate a Bookmark for the current row in the Dataset, and adds or removes the Bookmark based on the AValue argument. The Grid control is redrawn after changing the selection state for the row.

Provides indexed access to Bookmarks in the list

Items is a read-only TBookmark property that provides indexed access to Bookmarks in the list. Bookmarks can be accessed by their ordinal position in the list (in the range 0..Count-1).

GetItem is the read access specifier for the Items property, and retrieves the TBookmark stored at the specified position in the list.

Items is the default property in TBookmarkList.

Use CurrentSelectedRow, Clear, Delete, and Refresh to maintain bookmarks stored in the list.

Ordinal position for the bookmark to retrieve from the list Gets an enumerator for the bookmark list

GetEnumerator is a TBookmarkedRecordEnumerator function used to get an enumerator for bookmarked records in the list. GetEnumerator creates an instance of TBookmarkedRecordEnumerator with the specified arguments, and uses the instance as the return value for the method.

TBookmarkedRecordEnumerator
The bookmark list enumerator Options to use in the bookmark list enumerator Enumerated type defining alternate ordering for columns

TColumnOrder is an enumerated type which defines alternate ordering for columns in a collection. The values specify whether the design-time or run-time index is used when ordering TColumn instances in the TDBGridColumns collection.

TColumn TDBGridColumns TDBGrid.Columns
Columns are ordered using the DesignIndex value Columns are order by the Index for the Field Maintains an association between a component and a dataset

TComponentDataLink is a TDatalink descendant that maintains an association between a component and its linked dataset. TComponentDataLink coordinates the actions of the component and the dataset, and allows the component to respond to data events. TComponentDataLink defines event handlers which can be used to forward dataset events to the component implementation.

TComponentDataLink is the type used to implement the TDBGrid.DataLink property.

TDBGrid.DataLink
Gets the value for the DatasetName property

GetDatasetName is a String function that provides the value for the DataSetName property. GetDatasetName returns the value in the Name property for the DataSet.

Use DatasetName to read or write the value for the property.

Name for the linked dataset Gets the Field at the specified position

GetFields is a TField function that implements read access for the Fields property. GetFields returns the TField instance at the specified position in the Fields for the dataset. The return value is Nil if Index is not in the range 0..FieldCount-1.

Use Fields to read or write values in the property.

Field stored at the specified position Position to get from the Fields in the dataset Sets the name for the dataset

SetDatasetName is a procedure used to store the specified value in the DatasetName property. SetDatasetName is the write access specifier for the DatasetName property. The value in AValue is stored in the member variable for the class instance. It does not change the value stored the linked TDataset.

Use DatasetName to read or write the value for the property.

Name to use for the dataset Signals the OnRecordChanged event handler when assigned

RecordChanged is an overridden procedure used to signal the OnRecordChanged event handler when the specified Field is changed. RecordChanged calls the event handler when it has been assigned in the class instance. No action is performed when OnRecordChanged has not been assigned.

TDataLink.RecordChanged TComponentDataLink.OnRecordChanged TDBGrid.OnRecordChanged
Modified Field for the event notification Signals the OnDatasetChanged event handler when assigned

DatasetChanged is a procedure used to signal the OnDatasetChanged event handler when the dataset has been changed. DatasetChanged calls the event handler when it has been assigned in the class instance. No action is performed when OnDatasetChanged has not been assigned.

TDataLink.DatasetChanged TComponentDataLink.OnDatasetChanged TDBGrid.OnDatasetChanged
Signals an event handler when the Active property is changed

ActiveChanged is a procedure used to call event handlers when the value in Active is changed.

When Active contains True, the Dataset for the class is read and compared to the value in the DatasetName property. When it differs from the stored value the change is for a new dataset, and the OnNewDataset event handler is signalled. If DatasetName is the same as the stored value, the OnDataseOpen event handler is signalled.

When Active contains False, the Datasource and Dataset are checked to ensure that the contain valid class instances. If Datasource is unassigned, the OnInvalidDataSource event handler is signalled. If Dataset is unassigned, the Dataset is being freed, and the OnInvalidDataSet event handler is signalled. If Dataset is assigned, the dataset has been closed and the OnDataSetClose event handler is signalled.

TDataLink.ActiveChanged
Signals the OnLayoutChanged event handler when assigned

LayoutChanged is a procedure used to signal the OnLayoutChanged event handler when assigned in the class instance.

TDataLink.LayoutChanged TDBGrid.OnLayoutChanged
Signals the OnDataSetScrolled event handler when assigned

DatasetScrolled is a procedure used to signal the OnDataSetScrolled event handler when it has been assigned in the class instance.

TDataLink.DatasetScrolled TDBGrid.OnDataSetScrolled
Number of records for the event notification Signal the OnFocusControl event handler when assigned

FocusControl is a procedure used to signal the OnFocusControl event handler when assigned in the class instance.

Field receiving focus in the event notification Calls the inherited method

CheckBrowseMode is a procedure used to call the inherited method.

Signals the OnEditingChanged event handler when assigned

EditingChanged is a procedure used to signal the OnEditingChanged event handler when assigned in the class instance.

TDataLink.EditingChanged
Signals the OnUpdateData event handler when assigned

UpdateData is a procedure used to signal the OnUpdateData event handler when assigned in the class instance.

TDataLink.UpdateData
Moves the position in the dataset by the specified number of rows

MoveBy is an Integer function used to move the current position in the dataset by the specified number of rows. MoveBy calls the inherited method.

Actual number of rows moved in the method Number of rows to move in the dataset Indicates if the component or the linked dataset has been changed

Modified is a Boolean property that indicates if the component or the linked dataset has been changed.

OnRecordChanged - event handler for a change in the current record OnDataseChanged - event handler for a change in the attached dataset OnNewdataset - event handler for formation of a link to a new dataset OnDataseOpen - event handler when the dataset is open OnInvalidDataset - event handler when the dataset is invalid OnInvalidDataSource - event handler when the data source is invalid Event handler signalled when the grid control receives focus

OnFocusControl is a TFocusControlEvent property that implements an event handler signalled when the grid control receives focus.

TFocusControlEvent
OnLayoutChanged - event handler when the layout of the dataset has changed OnDataseClose - event handler when the dataset is closed OnDataseScrolled - event handler when the dataset is scrolled OnEditingChanged - event handler for a change in the Editing property OnUpdateData - event handler for implementing any pending changes to data DatasetName - the (string) name of the attached dataset Fields - an indexed array containing the Fields of the dataset TColumnTitle is a TGridColumnTitle descendant

TColumnTitle is a TGridColumnTitle descendant which ensures the correct caption is used as the title for a column in a data-aware grid.

Gets the default caption used as the title for the grid column

GetDefaultCaption is an overridden String function in TColumnTitle which provides the default caption used as the title for a grid column.

If a Field has been created for the column, the value of its DisplayName property is used as the caption. If only the FieldName property is set, it is used as the caption. Otherwise, the inherited method is called to get the default caption for the column.

TField TColumn TGridColumnTitle.GetDefaultCaption
Default value used as the title for the column Implements a display column for the TDBGrid control

TColumn is a TGridColumn descendant that represents a display column in a database grid control. TColumn extends the ancestor class to provide support for using TField for data access, display formatting, alignment, as well as use of checkbox and lookuplist Fields. TColumn also implements support for features in TDBGrid like: automatic rows, and design-time vs run-time column ordering.

TColumn provides properties and methods needed to access and maintain the Dataset, Field, FieldName, and DisplayFormat for the column. TColumn provides overridden functions which implement facilities from the ancestor class.

TColumn instances can be created at run-time or design-time; properties are provided to indicate when the instance was created. The display order for columns need not correspond to the order of the Fields in the dataset, nor do all Fields in the dataset need to be represented by a display column.

TColumn instances are used as the collection item for the TDBGridColumns collection.

TColumn is the class type used for items in the TDBGridColumns collection.

TDBGrid.Columns TDBGridColumns TGridColumn TField TDataset
Applies a new display format to the Field which gets data for the column

ApplyDisplayFormat is a procedure used to apply a new value in DisplayFormat to the Field used to get data for the column. Field must contain a valid TField instance, or no actions are performed in the method.

ApplyDisplayFormat ensures that the new value for DisplayFormat is properly applied to Fields using the TNumericField or TDateTimeField class types. ApplyDisplayFormat is used in the implementation of the LinkField method.

TColumn.LinkField
Gets the Dataset for the column

GetDataset is a TDataset function used to get the dataset which provides data for the column. GetDataset uses Grid (cast to a TCustomDBGrid instance) to access its DataLink and get the DataSet for the column definition. The return value is Nil if Grid has not been assigned for the column.

TGridColumn.Grid TCustomDBGrid TDataset
Dataset for the column definition Get the value for the DisplayFormat property

GetDisplayFormat is a String function used to get the value for the DisplayFormat property. The value in the member variable is returned when it is different than the stored value for DisplayFormat. Otherwise, the value from GetDefaultDisplayFormat is used as the return value.

Use DisplayFormat to read and write the value for the property.

Value for the DisplayFormat property Gets the value for the Field property

GetField is a TField function used to get the value for the Field property. GetField ensures that Field has been assigned, and that FieldName has been set for the class instance. The LinkField method is called to find and store the TField instance used as the return value for the method. The return value is Nil if a Field with the name in FieldName cannot be found.

Use Field to read or write the value in the property.

TColumn.Field TColumn.LinkField TField
Field used to access data for the column Gets the value for the IsDesignColumn property

GetIsDesignColumn is a Boolean function used to get the value for the IsDesignColumn property. The return value is True when DesignIndex contains a value in the range 0..9999.

The upper range for DesignIndex is a result of the value assigned in Create. The value 10000 is used in the property when Grid has not assigned for the collection, or Grid includes csLoading in its ComponentState property.

Use IsDesignColumn to read the value for the property.

TColumn.DesignIndex TDBGridColumns TDBGrid.Columns
Value for the IsDesignColumn property Determines the storage specifier for the DisplayFormat property

IsDisplayFormatStored is a Boolean function used as the storage specifier for the DisplayFormat property. The return value is True if the member variable for the DisplayFormat property is different than the one used for the Field.

True when DisplayFormat is different the one used for the Field Sets the value in the DisplayFormat property

SetDisplayFormat is a procedure used to set the value in the DisplayFormat property. SetDisplayFormat compares the value stored in the member variable to the new value for the property. If they are different, the new value is stored and a flag is set to indicate that the display format has changed. SetDisplayFormat calls the ColumnChanged method to indicate that the column definition has been updated.

No actions are performed in the method when the DisplayFormat has not been changed.

Use DisplayFormat to read or write the value for the property.

Sets the value in the Field property

SetField is a procedure used to set the value in the Field property. SetField compares the new value for the property to the value stored in the member variable. When they are different, the new value is stored in the member variable. If the new value is not Nil, its FieldName is updated as well. SetField calls the ColumnChanged method to indicate that the column definition has been updated.

No actions are performed in the method when the new Field value is the same as the value stored in the member variable .

Use Field to read or write the value for the property.

TColumn.Field TColumn.FieldName
Sets the value in the FieldName property

SetFieldName is a procedure used to set the value in the FieldName property. SetFieldName compares the new value to the value stored in the member variable for the property. No actions are performed in the method when they are the same.

SetFieldName stores the new value for the property in its member variable, and calls the LinkField method to find the Field with the specified name. DisplayFormat is updated when a matching Field is located in the dataset for the column.

TColumn.LinkField TColumn.DisplayFormat
Creates the title used for the grid column

CreateTitle is an overridden TGridColumnTitle function used to create the title used as a fixed caption for the column.

Title for the column Gets the default alignment for the Field in the column definition

GetDefaultAlignment is an overridden TAlignment function that gets the default alignment for the Field in the column definition. GetDefaultAlignment gets the button style used by the default editor for Field. For checkbox and button-style editors, center alignment is used. Otherwise, the Alignment in Field is used. If Field has not been assigned, left alignment is used.

Alignment for the Field and/or editor style Gets the default display format for the Field in a column

GetDefaultDisplayFormat is a String function used to get the default display format provided for the Field in a column definition. GetDefaultDisplayFormat uses the Field property to get its DisplayFormat for use as the return value in the method. The return value is a empty string ('') when Field has not been assigned for the column definition.

GetDefaultDisplayFormat is used in the implementation of the GetDisplayFormat method.

TColumn.Field TColumn.GetDisplayFormat TField.DisplayFormat
Default display format for the Field in the column Gets the default value for a Checkbox in the Checked state as a String

GetDefaultValueChecked is an overridden String function used to get the default value used for a Checkbox column in the Checked state. When Field has been assigned for the column, and the data type is ftBoolean, the return value is 'TRUE'. If Field has not been assigned, the return value is '1'.

'TRUE' or '1' Gets the default String value for a Checkbox in the UnChecked state

GetDefaultValueUnchecked is an overridden String function used to get the default value used for a Checkbox column in the UnChecked state. When Field has been assigned for the column, and the data type is ftBoolean the return value is 'FALSE'. If Field has not been assigned, the return value is '0'.

'FALSE' or '0' Indicates if the Field for the column is Visible

GetDefaultVisible is an overridden Boolean function that indicates if the Field for the column is Visible. GetDefaultVisible uses Field to get its Visible property for use as the return value in the method. If Field has not been assigned in the column, the return value is True.

True when the Field for the column is visible Gets the display name for the collection item

GetDisplayName is an overridden String function used to get the display name for the column. The display name is used at design-time to get the name for the collection item, and at run-time when a dataset for the column has not been assigned or opened.

The value in FieldName is used as the return value for the method, when it has been assigned in the column. Otherwise, the inherited GetDisplayName method is called to get the return value.

Use FieldName to set the name of the Field used for the column.

TColumn.FieldName TCollectionItem.GetDisplayName
Display name for the collection item Gets the default value for the ReadOnly property

GetDefaultReadOnly is an overridden Boolean function which gets the default value for the ReadOnly property. GetDefaultReadOnly combines the ReadOnly values found in both the Grid and the Field for the dataset to derive the value for the method. The return value is True when Grid or Field is not assigned for the column.

TGridColumn.GetDefaultReadOnly TGrid.ReadOnly TField.ReadOnly
Effective value for the ReadOnly property Gets the effective width for the column

GetDefaultWidth is an overridden Integer function used to get the effective width for the column. The return value is calculated using the Grid and its Canvas to find the space needed for the Field in the column. When the Grid has Options that include the value dgTitles, Title.Caption and Title.Font are included in the calculation. GetDefaultWidth calls the CalcColumnFieldWidth function to get the canvas width used as the return value.

The return value is -1 if the Grid has not been assigned for the column. The return value contains Grid.DefaultColWidth when Field has not been assigned in the column.

TGridColumn.GetDefaultWidth CalcColumnFieldWidth
Effective width for the the column Gets the values in the pick list for the column

GetPickList is an overridden TStrings function which gets the values in the pick list for the column. GetPickList calls the inherited method, and provides support for Lookup Fields in the column definition.

When Field is assigned and contains a Lookup Field (fkLookup in its FieldKind property), values from the LookupList or the LookupDataset are included in the return value. When LookupDataset is used, the result includes values from the LookupResultField for each of the rows in the dataset.

TGridColumn.GetPickList TField
Values available for the lookup-style column Indicates if the column was automatically added at run-time

IsAutomaticColumn is a read-only Boolean property that indicates if the column was automatically added to the collection at run-time. The value in IsAutomaticColumn is updated when TDBGrid.AddAutomaticColumns and TDBGridColumns.RemoveAutoColumns add or remove items in the collection.

Use IsDesignColumn to determine if the column was added at design-time. Use TDBGridColumns.HasAutomaticColumns to determine if any automatic columns are stored in the collection. Use TDBGrid.OptionsExtra to enable or disable automatically columns in a database grid control.

TColumn.IsDesignColumn TDBGridColumns TDBGrid.Columns TDBGrid.OptionsExtra
Indicates if the column was added at design-time

IsDesignColumn is a read-only Boolean property which indicates if the column was added at design-time. GetIsDesignColumn is the read access specifier for the IsDesignColumn property.

Use IsAutomaticColumn to determine if the column was added at run-time. Use TDBGridColumns.HasDesignColumns to determine if any design-time columns are stored in the collection.

TColumn.IsAutomaticColumn TDBGridColumns.HasDesignColumns TDBGrid.OptionsExtra
Establishes a link between the FieldName and the Field in a Dataset

LinkField is a procedure used to establish a link between the FieldName in the column and the Field in its Dataset. LinkField requires Grid to be assigned in order to access the DataLink and its Dataset. When Grid is unassigned, the value for Field is Nil. The DataLink in Grid must be Active to access the Fields in the dataset. When DataLink in not Active, the value in Field is Nil.

LinkField finds the Field in the linked dataset with the name specified in FieldName. The TField instance is stored in the Field property. LinkField calls the ApplyDisplayFormat method to update the DisplayFormat used for the column.

LinkField is called when reading the value for the Field property and it has not already been assigned.
TColumn.Field TColumn.DisplayFormat TColumn.ApplyDisplayFormat TDBGrid.DataLink
Constructor for the TColumn instance

Create is the constructor for the TColumn instance. Create calls the inherited Create constructor and sets the DesignIndex used for the new entry in the TCollection. Create is called by the TCollection.Add method and should not be called directly under normal circumstances.

TGridColumn.Create TCollection
Collection that owns the collection item Stores properties from a persistent class in the current class instance

Assign is an overridden procedure which stores properties from Source in the current class instance. Assign calls the inherited Assign method. When Source is a TColumn class instance, the values for the following are stored in the current class instance:

  • FieldName
  • DisplayFormat
  • ValueChecked
  • ValueUnchecked
TPersistent.Assign
Persistent class with values stored in the method Indicates if the column uses its default display format

IsDefault is an overridden Boolean function that indicates if the column uses its default display format. The return value is True when the value in the DisplayFormat property has not been changed. IsDefault calls the inherited method to get the return value for the method.

True when DisplayFormat has been changed Field in the Dataset associated with this Column

Field is a TField property that provides access to the content and other attributes for the dataset Field represented by the column. GetField reads the value for the property. SetField writes the value for the property.

TField TColumn.LinkField
Order for the column in its collection at design-time

DesignIndex is a read-only Integer property that contains the order for the column in its collection at design-time. The value in DesignIndex is used primarily when TDBGridColumns.ResetColumnsOrder compares and sorts the items in its collection.

TColumn.Create TDBGridColumns.ResetColumnsOrder CompareDesignIndex
The format to be used for display in this column

DisplayFormat is a String property which specifies a format string used for displaying the value of a Field with the name in FieldName. Use of DisplayFormat in TColumn is consistent with its use in TField (and decendants), but can assign a value that overrides the default display format for the Field.

GetDisplayFormat is the read access specifier for the property. SetDisplayFormat is the write access specifier for the property. Changing the value in DisplayFormat causes the ColumnChanged method to be called when the column definition has been updated.

Name of the Field with data for the column

FieldName is a String property which contains the name of the Field used to get data for the column. SetFieldName is the write access specifier for the property. Changing the value in FieldName causes LinkField to be called to find the Field with the specified name. The value in DisplayFormat is also modified when the property was has changed.

Implements a collection for columns in a database grid

TDBGridColumns is a TGridColumns descendant which implements a collection for columns added to TDBGrid.

TDBGridColumns extends the ancestor class to include support for adding and removing automatic columns at run-time. Automatic columns are a feature in TDBGrid that, when enabled, ensures the collection has a column definition for each Field in the linked dataset for its grid control. Methods and Properties are provided to identify columns added at run-time, and to order entries in the collection by their design-time or run-time indices.

Items is the default property for the collection. TColumn is the class type used for Items added to the collection.

Use the Add method to create a new collection item in the Items property. Use LinkFields to update the association between an item in the collection and the TField used to access its data. Use ResetColumnsOrder to change the order of Items in the collection.

Gets the collection item stored at the specified position

GetColumn is a TColumn function which gets the column at the specified position in the collection. GetColumn is the read access specifier for the Items property.

Use Items to read and write values in the collection.

Collection item at the specified position Position in the collection Stores the collection item at the specified position

SetColumn is a procedure which stores the column in Value at the specified position in the collection. SetColumn is the write access specifier for the Items property. SetColumn uses the Assign method to store the new Value in the collection.

Use Items to read and write values in the collection.

Position where the collection item is stored Collection item to store at the specified position Redraws the Grid control that owns the column collection

Update causes the TDBGrid control which owns the column collection to be redrawn. The value in Grid must be assigned, or no actions are performed in the method. In addition, the Grid control will not be updated if component streaming is active (csLoading in its ComponentState). Update calls TDBGrid.LayoutChanged to force the Grid control to be redrawn.

TCollection.Update
Collection item triggering the update ColumnFromField returns the collection item for the specified Field

ColumnFromField returns the collection item for the specified Field. The return value is Nil when Field has not been assigned.

ColumnFromField iterates over the Items in the collection to locate the specified Field. The return value is Nil when Field cannot be located in the Items for the collection.

ColumnFromField is used in the TDBGrid.AddAutomaticColumns method.

Collection item for the specified Field Field to locate in the collection Add creates and stores a new item in the collection

Add creates and stores a new TColumn instance in the collection.

Add uses the Grid property (and the value in its GridStatus property) to determine whether the column is being explicitly added to the collection or added as a result of the automatic columns option in the grid. If the Grid contains the value gsAddingAutoColumns in its GridStatus property, existing automatic columns are left in the collection. Otherwise, RemoveAutoColumns is called prior to creating and storing the new TColumn instance.

Add calls the inherited Add method to create and store the new TColumn instance.

TCollection.Add
TColumn added to the collection Associates column items with the corresponding Fields in the Dataset

LinkFields is a procedure which associates column items to the corresponding Fields in the Dataset for the Grid. LinkFields uses Grid to call its BeginLayout and EndLayout methods prior to and immediately after linking the Items in the collection to fields in the Dataset. This forces the Grid control to be updated when the method has completed. LinkFields calls the TColumn.LinkField method for each of the Items in the collection.

Items provides indexed access to columns added to the collection

Items is a TColumn property that provides indexed access to columns in the collection by their ordinal position (in the range 0..Count-1). Read and write access to columns in the Items property are cast to the TColumn class type used in the collection. Write access calls the Assign method in the TColumn instance stored at the specified position.

Items is the default property for the collection.

Position for the collection item HasAutomaticColumns indicates if any items in the collection are an automatic column

HasAutomaticColumns is a Boolean function that indicates if any items in the collection are an automatic column added at run-time. Automatic columns are a feature in TDBGrid enabled by adding the appropriate value to its OptionsExtra property. HasAutomaticColumns returns True if a TColumn instance in the Items property has its IsAutomaticColumn property set.

TDBGrid.OptionsExtra TDBGridColumns.RemoveAutoColumns
True when automatic columns are stored in the collection HasDesignColumns indicates if the collection contains any items explicitly added at design-time

HasDesignColumns is a Boolean function that indicates if the collection contains any items explicitly added at design-time. HasDesignColumns returns True if Items contains a TColumn instance with its IsDesignColumn property set.

TDBGridColumns.Items TColumn.IsDesignColumn TColumn.ResetColumnsOrder
True an item has its IsDesignColumn property set RemoveAutoColumns removes automatic columns in the collection

RemoveAutoColumns is a procedure used to remove any automatic columns in the collection. RemoveAutoColumns uses HasAutomaticColumns to determine if any action is required.

When HasAutomaticColumns returns True the Grid updates its GridStatus to include the value gsRemovingAutoColumns. RemoveAutoColumns calls the Delete method for any column having its IsAutomaticColumn property set to True. gsRemovingAutoColumns is removed from the GridStatus property in the Grid prior to exiting from the method.

Applications do not normally call the RemoveAutoColumns method. Use TDBGrid.OptionsExtra to disable the automatic columns feature in the grid control.

TDBGrid.GridStatus TDBGrid.OptionsExtra
ResetColumnsOrder arranges columns in the collection to the specified order

ResetColumnsOrder is a procedure used to arrange columns in the collection to the order specified in the ColumnOrder argument. ColumnOrder can contain the following values:

coDesignOrder
TColumn.DesignIndex (when available) is used to order collection items.
coFieldIndex
The index for the TColumn.Field (when available) is used to order collection items.

Otherwise, the index of the collection item is unchanged.

Sort order for columns in the collection TCustomDBGrid is the base class for TDBGrid

TCustomDBGrid is a TCustomGrid descendant and the base class for TDBGrid. TCustomDBGrid adds capabilities needed to implement a database-aware grid control. One key feature is the TComponentDataLink in DataLink used to coordinate access and event handlers between the grid control and its linked dataset. Another key feature is the use of the Options and OptionsExtra properties to enable/disable features or behaviors in the grid control.

TCustomDBGrid overrides certain features from the ancestor class to provide consistent use with Fields, Field kinds, and values in TDataset.

Applications should use the TDBGrid descendant which sets the scope of properties, methods, and event handlers to public or published.

HowToUseGrids HowToUseDataAwareControls
Gets the value in the SelectedField property

GetCurrentField is a TField function used to get the value in the SelectedField property. GetCurrentField is the read access specifier for the SelectedField property. GetCurrentField calls GetFieldFromGridColumn to get the TField instance used as the value for the property.

Use SelectedField to read and write value for the property.

Value for the SelectedField property Gets the value for the DataSource property

GetDataSource is a TDataSource function used to get the value for the DataSource property. GetDataSource is the read access specifier for the DataSource property. GetDataSource gets the DataSource property stored in DataLink as the return value for the method.

Use DataSource to read or write values in the property.

Value for the DataSource property Gets the number of records in the linked dataset

GetRecordCount is an Integer function used to get the number of records in the linked dataset. GetRecordCount uses the DataLink for the grid to get the RecordCount in its DataSet property. The record count is used as the return value for the method.

Number of records in the linked dataset Default implementation for the event handler in TComponentDataLink

OnRecordChanged is a procedure which provides a default implementation for the OnRecordChanged event handler in TComponentDataLink. OnRecordChanged ensures that the grid control and the linked dataset are synchronized when refreshing the active record, selecting the current column, and re-enabling the edit control when EditMode is active.

Default implementation for the event handler in TComponentDataLink

OnDatasetChanged is a procedure which provides a default implementation for the OnDatasetChanged event handler in TComponentDataLink.

Implementation for the event handler in TComponentDataLink

OnDatasetOpen provides a default implementation for the event handler in TComponentDataLink.

Implementation for the event handler in TComponentDataLink OnDatasetClose provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnEditingChanged provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnInvalidDataSet provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnInvalidDataSourcet provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnLayoutChanged provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnNewDataset provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnDatasetScrolled provides a default implementation for the event handler in TComponentDataLink. Implementation for the event handler in TComponentDataLink OnUpdateData provides a default implementation for the event handler in TComponentDataLink. Not used in the current implementation. Not used in the current implementation.

SetCurrentField is a procedure used to set the value in the SelectedField property. SetCurrentField is the write access specifier for the SelectedField property. SetCurrentField calls GetGridColumnFromField to ensure that the Field in AValue becomes the current column in the control. No actions are performed in the method when AValue contains the same value as the SelectedField property.

Use SelectedField to read or write the value for the property.

Field to select in the method Sets the value in the DataSource property

SetDataSource is a procedure used to set the value in the DataSource property. SetDataSource is the write access specifier for the DataSource property. SetDataSource stores the value in AValue in the DataSource property for DataLink, refreshes the column widths for the control, and calls UpdateActive.

Use DataSource to read or write the value in the property.

New data source for the property value Sets the values in the Options property

SetOptions is a procedure used to set the values in the Options property. SetOptions is the write access specifier for the Options property. SetOptions causes other aspects of the grid control to be updated to reflect changes in the property value. ChangedOptions is updated to reflect the enumeration values added or removed in the request. Some enumeration values force other features or behaviors to be disabled. For instance: row selection. Enabling row selection forces the options for editing, always displaying the editor, and row highlighting to be removed from the Options property. Finally, removing multi-selection from the Options property forces the SelectedRows and KeyBookmark properties to be cleared.

AValue is a TDBGridOptions argument that specifies features or behaviors that will be enabled or disabled in the grid control. Please note that these options are different than the TGridOption values used in the ancestor class.

As a result, SetOptions must translate any TDBGridOption values to their TGridOption equivalents and store them in the inherited Options property.

Options contains the following default values when the control is created:

  • dgColumnResize
  • dgColumnMove
  • dgTitles
  • dgIndicator
  • dgRowLines
  • dgColLines
  • dgConfirmDelete
  • dgCancelOnExit
  • dgTabs
  • dgEditing
  • dgAlwaysShowSelection

See TDBGridOption for more information about values in the enumeration.

New values for the Options property Sets the number of records buffered for the linked dataset

UpdateBufferCount is a procedure used to set the number of records buffered for the linked dataset. UpdateBufferCount requires that DataLink be marked as Active to set the buffer count. If DataLink.Active contains False, no actions are performed in the method.

UpdateBufferCount calls GetBufferCount to determine the number of rows that can be displayed in the control with the DefaultRowHeight. When Options includes the value dgTitles, the buffer count is decreased by 1 to account for the fixed title row. UpdateBufferCount stores the new value in the BufferCount property in DataLink.

UpdateBufferCount is called from the UpdateGridCounts method.

UpdateData is used to perform pending updates for the selected cell.

UpdateData is a virtual procedure used to perform pending updates for the selected cell to its Field in the grid Dataset. No action is performed if the selected cell has not been modified (or cannot be modified) or the Dataset is not in edit mode.

UpdateData ensures that the appropriate method is used to update Field data based on the TField.FieldKind for the modified column. Special handling is provided for lookup Fields to check the cached lookup list or to retrieve the lookup result using its key Fields.

UpdateData calls the EditingColumn method to disable the editing flag for the column prior to exit.

Gets the number of visible columns or Fields in the grid

GetColumnCount is an Integer function used to get the number of visible columns or Fields for the grid control. GetColumnCount uses the Columns collection (when its has been Enabled) to get the value in VisibleCount. When Columns is not Enabled, and OptionsExtra has dgeAutoColumns enabled, the linked dataset is used to determine the number of Fields with their Visible flag set. The Dataset cannot be examined if the DataLink is not marked as Active.

GetColumnCount is called from the UpdateGridCounts method.

Number of visible Fields or columns in the grid Gets the default column width for the specified Field

DefaultFieldColWidth is an Integer function used to get the default column width for the specified Field. When the specified Field contains Nil, the value from DefaultColWidth is used. Otherwise, the DisplayWidth property in the TField instance is used to get the Canvas.TextWidth for the DisplayName in the Field.

Default column width for the field Field to examine in the method GetDsFieldFromGridColumn returns the identity of the dataset Field corresponding to the nominated grid column

GetDsFieldFromGridColumn returns the identity of the dataset Field corresponding to the nominated grid column

Field to use for the specified column Column with the field to locate in the method GetFieldFromGridColumn obtain the Field either from a Db column or directly from dataset Fields

GetFieldFromGridColumn obtain the Field either from a Db column or directly from dataset Fields.

Field for the specified column Column to locate in the method GetGridColumnFromField - gets the corresponding grid column for the given Field

GetGridColumnFromField - gets the corresponding grid column for the given Field.

Column for the specified field Field to locate in the grid columns FieldIndexFromGridColumn returns the index for the database Field corresponding to the stated grid column

FieldIndexFromGridColumn returns the index for the database Field corresponding to the stated grid column.

Position of the field for the specified column Column to locate in the fields for the control Updates sizes for automatically sized columns in the grid

UpdateGridColumnSizes is a procedure used to update the sizes for automatically sized columns in the grid control. UpdateGridColumnSizes requires DefaultColWidths to be in use for the grid. No actions are performed in the method when DefaultColWidths contains False.

UpdateGridColumnSizes also requires the Options property to include the value dgAutoSizeColumns which enables the auto-sized columns feature. No actions are performed if the feature has not been enable for the grid control.

UpdateGridColumnSizes calls the UpdateAutoSizeColumns method to calculate the widths for the auto-sized columns.

Update the grid and its scrollbars when its layout has changed

DoLayoutChanged is a procedure used to update the grid and its scrollbars when the layout for the control has changed. No actions are performed in the method when the control is freed (contains csDestroying in its ComponentState).

DoLayoutChanged calls BeginUpdate to signal changes to the control, and UpdateGridCounts to determine the number of rows for the update. When UpdateGridCounts returns 0, the EmptyGrid method is called to clear the grid control. DoLayoutChanged calls EndUpdate to allow pending changes to be applied to the control. DoLayoutChanged calls UpdateScrollbarRange to update scrollbars (when used) for the control.

DoLayoutChanged is called from the EndLayout method.

Not used in the current implementation. Re-enables the editor control after scrollbar messages

RestoreEditor is a procedure used to re-enable the editor control in the grid after processing scrollbar messages. RestoreEditor is used when EditorMode contains True. No actions are performed in the method when EditorMode contains False. RestoreEditor toggles the value in EditorMode to force the editor to be refreshed and redrawn.

Indicates if the linked dataset is positioned at the end-of-file

ISEOF is a Boolean function used to indicate if the linked dataset is positioned at the end-of-file. ISEOF uses the DataLink for the control to access its Active and Dataset properties. DataLink must be Active (contains True) to access its Dataset. The return value is True when the TDataset.EOF method returns True. The return value is False when DataLink is not Active, or TDataset.EOF returns False.

ISEOF is used in the KeyDown and MouseDown methods.

EOF state for the linked dataset BeginLayout starts producing layout changes for the grid control

BeginLayout is a procedure which starts producing layout changes for the grid control. BeginLayout is used along with EndLayout to minimize the number of times layout changed notification events are triggered by the control. Layout changes occur when the control enables certain values in its Options property, when AutoAdjustColumn is called, and when the Columns collection links to Fields in the associated dataset.

BeginLayout increments the LayoutChangedCount variable that tracks the number of times the method is called for the control. EndLayout decrements that counter, and when it reaches 0 (zero), the DoLayoutChanged method is called.

CellClick calls the OnCellClick event handler if it is assigned for this particular cell

CellClick calls the OnCellClick event handler if it is assigned for this particular cell.

Indicates if the field is a Memo that needs to be displayed in the grid

CheckDisplayMemo is a Boolean function used to determine if the specified field is a Memo field that needs to be displayed in the grid control. The return value is True when the specified field has the value ftMemo in its DataType property, and the Options property has enabled the dgDisplayMemoText feature.

Signals event handlers when a row or a column is moved in the grid control

ColRowMoved is an overridden procedure used to signal event handlers when a row or a column is moved in the grid control. When IsColumn contains False, the OnRowMoved event handler is signalled (when assigned). When IsColumn contains True, the OnColumnMoved event handler is signalled (when assigned) if Columns have not been Enabled in the grid control. If Columns have been Enabled, the inherited ColRowMoved method is called.

Creates the Columns collection for the grid control

CreateColumns is an overridden TGridColumns function used to create the Columns collection for the grid control. In TDBGrid, the Columns collection is implemented using the TDBGridColumns class type (a descendant of TGridColumns). CreateColumns creates an instance of TDBGridColumns which is used as the return value for the method.

Columns collection for the grid control CreateWnd - creates the window adjusts its layout and adds scrollbars when needed TWinControl.CreateWnd Provides an empty implementation that avoids calling the inherited DefineProperties method. TCustomGrid defines ColWidths, RowHeights and Cells properties which do not use facilities available in the data-aware grid control. Default method used to drawing a cell at the specified location

DefaultDrawCell is a procedure that provides the default method for drawing a cell at the specified location using different cell types. DefaultDrawCell draws the background for the cell with the specified drawing state. For a cell which appears in a fixed row or column, the text for the cell is also drawn.

When the DataSet for the grid control has rows, the Field used for the specified column is retrieved and the cell is drawn in the manner needed for its column editor style. For checkbox columns, the DrawCheckBoxBitmaps is called. For columns with a button-style editor, the DrawButtonCell method is used. For Fields with a ftMemo data type, the CheckDisplayMemo method is called to determine whether the content in the memo or the DIsplayText for the column definition is drawn. Finally, the DrawCellText method is called to draw the specified cell using its state and value.

DoExit closes the editor and the datalink for the control

DoExit is an overridden procedure in TCustomDBGrid used to close the editor and the datalink for the control. A valid dataset must be assigned in the DataLink property and inserts must be cancellable for the dataset. The Options property must include the dgCancelOnExit enumeration value for the grid. If any of these conditions are not met, no actions are performed in the method on either the dataset or the Field editor.

DoExit calls the inherited method to perform any actions implemented in the ancestor class.

TWinControl.DoExit
DoOnChangeBounds - calls inherited DoOnChangeBounds adjusts layout if required TControl.DoOnChangeBounds Draws the current selection in the grid in a focused state

DrawFocusRect is an overridden procedure used to draw the current selection in the grid in a focused state.

The grid control must have focus before the current selection can be drawn. In addition the DataLink for the control must refer to an active dataset. DrawFocusRect uses the Options property to ensure that dgAlwaysShowSelection has been included for the control. Finally DefaultDrawing must be enabled to allow drawing of the focus rectangle using the rubberband style on the Canvas for the control.

If any of the previous conditions are not met, no actions are performed in the method.

DrawRow is an overridden procedure used to draw the specified row number in the grid control.

ARow contains the row number to be drawn and refers to an ordinal position relative to the FixedRows for the control. When ARows contains a value that would be in the FixedRows the state flags that track drawing an active record or multi-selection are reset. DrawRow also requires that DataLink refer to an active dataset. No actions are performed in the method if these conditions are not satisfied.

DrawRow sets the active record in DataLink for selected rows in the control and updates the DrawingActiveRecord and DrawingMultiSelRecord flags as needed. The Options property must include the value dgMultiSelect to enable drawing of multiple selections in the control.

DrawRow calls the inherited method to perform any actions implemented in the ancestor class.

DrawCell renders the specified grid cell in the supplied drawing state

DrawCell is used to render a cell at the specified coordinates with the specified drawing state.

EditingColumn sets or resets the column being edited in the control

EditingColumn is a procedure used to set or reset the column being edited in the control .

aCol indicates the ordinal column number and is stored internally for use in other methods of the control. Ok indicates that editing is active when set and causes the DataLink to set its Modified flag to true. When Ok contains False the internal column number is reset to its default value indicating that no column is currently being edited.

EditingColumn is used in the implementation of other methods in the grid control such as UpdateData, EditorCancelEditing, EditorIsReadOnly, and DoExit.

TCustomDBGrid.UpdateData TCustomDBGrid.EditorCancelEditing TCustomDBGrid.EditorIsReadOnly TCustomDBGrid.DoExit
EditorCancelEditing cancels pending changes and disables the editor

EditorCancelEditing is a procedure used to cancel pending changes and to halt the editing process.

EditorCancelEditing calls the EditingColumn method to disable the editor in the currently selected cell for the control. The EditorMode property is cleared when set, but is restored if the Options property includes the value dgAlwaysShowEditor.

EditorCancelEditing is used in the implementation of methods like DoOperation MoveSel and MouseDown.

EditorDoGetValue gets the value used in the editor for the control

EditorDoGetValue is an overridden procedure used to get the value used in the editor for the control. EditorDoGetValue calls the inherited EditorDoGetValue method. UpdateData is called to retrieve the value for the editor from its column in the underlying dataset.

TCustomGrid.EditorDoGetValue
EditorCanAcceptKey determines if the specified character can be applied to the Field for the editor

EditorCanAcceptKey is an overridden Boolean function which determines if the cell editor can accept the character specified in ch. EditorCanAcceptKey requires that the linked dataset be active to access the SelectedField for the control. The Field cannot be an AutoIncrement, Lookup, Calculated, or Blob Field type. The return value is False if any of these conditions are not satisfied.

EditorCanAcceptKey calls the IsValidChar routine to determine if the UTF8-encoded value in ch can be applied to the dataset for the control.

TCustomGrid.EditorCanAcceptKey
Key to examine in the method True when the character can be applied to the field EditorIsReadOnly determines if the editor can be enabled for the selected cell in the control

EditorIsReadOnly is a Boolean function used to determine if the editor can be enabled for the selected cell in the control.

EditorIsReadOnly calls the inherited method to ensure that requirements from the ancestor class are respected. If the ancestor class returns True no actions are performed in the method.

EditorIsReadOnly locates the TField used to store data for the selected cell, and calls its CanModify method to determine if the Field can be modified. Additional logic is applied for lookup Fields; the TField.KeyFields for the Field are also examined to determine if any of them are marked as read-only.

EditorIsReadOnly ensures the dataset in DataLink is in edit mode. The GridStatus property is updated to include gsStartEditing prior to changing the dataset state, and removed from GridStatus after the dataset state has changed.

EditorIsReadOnly calls the EditingColumn method to synchronize the cell editor state to the value returned by the method.

True when an editor cannot modify the select cell EndLayout finishes layout changes for the control

EndLayout is a procedure used along with BeginLayout to minimize the number of times layout changed notification events are triggered by the control. Layout changes occur when the control enables certain values in its Options property when AutoAdjustColumn is called and when the Columns collection links to Fields in the associated dataset.

The grid maintains an internal counter that tracks the number of times BeginLayout has been called to start a layout change for the control. EndLayout decrements that counter, and when it reaches 0 (zero), the DoLayoutChanged method is called.

TCustomDBGrid.BeginLayout TCustomDBGrid.DoLayoutChanged TCustomDBGrid.LayoutChanged TCustomDBGrid.Options TCustomDBGrid.AutoAdjustColumn TDBGridColumns.LinkFields TDBGridColumns.Update
GetEditMask gets the EditMask for the Field at the specified Row and Column

GetEditMask is an overridden String function used to get the EditMask for the TField that reads and writes data for specified Row and Column.

The linked dataset for the grid control must be active to access the Field definition at the specified column number. GetEditMask calls the GetFieldFromGridColumn method to get the TField instance with the EditMask for the column.

The return value can contain an empty string ('') is the dataset is not active, or a Field cannot be located for the specified column, or the EditMask has not been assigned in the Field definition.

GetEditMask signals the OnFieldEditMask event handler when it has been assigned for the control. Use OnFieldEditMask to return a user-specified value for the EditMask.

TCustomGrid.GetEditMask
Edit mask for the specified cell Column in the grid Row in the grid GetEditText gets the Text value for the specified Field

GetEditText is an overridden String function used to get the Text value for the Field at the specified Row and Column.

GetEditText requires that the linked dataset for the control be active to access its Field definitions. GetEditText calls the GetFieldFromGridColumn method to get the TField instance that provides the textual representation of the value for the Field. GetEditText calls the CheckDisplayMemo method to determine if a Field with the ftMemo data type displays its content or the string literal in its Text property '(Memo)'.

Text value displayed for the specified cell Column in the grid` Row in the grid GridCanModify indicates if the DataLink is active and allows editing

GridCanModify indicates if the DataLink is active, and allows editing.

True when the grid can be modified HeaderClick - calls OnHeaderClick if assigned

HeaderClick - calls OnHeaderClick if assigned.

TCustomGrid.HeaderClick
Updates Columns in the control when a a header cell is resized

HeaderSized is an overridden procedure which updates the Columns for the control when a header cell is resized. If IsColumn contains False the resize operation was for the height of a header row and no action is performed in the method. When IsColumn contains True the request applies to the width of the column with the Field at the position specified in Index.

HeaderSized calls the ColumnIndexFromGridColumn method to determine the position in the Columns collection for the Field specified in Index. The width in Columns is updated with the corresponding value from ColWidths. HeaderSized sets the value in DefaultColWidths to False to indicate that custom column sizing has been applied to the control.

HeaderSized signals theOnColumnSized event handler when assigned for the control.

Sizing applies to a column and not a row Ordinal position for the column KeyDown handles special keys and signals the OnKeyDown event handler

KeyDown ensures that keys which affect navigation and editing operations are handled in the grid control. KeyDown handles the following keys:

Tab
Advances to the next column when dgTabs is included in Options. Otherwise exits the control.
Shift + Tab
Moves to the previous column when dgTabs is included in Options. Otherwise exits the control.
Return
Enables the editor for the cell when dgEditing is included in Options. Otherwise advances to the next column.
Ctrl + Delete
Deletes the selected row when dgDisableDelete has not been included in Options. A confirmation dialog is displayed when dgConfirmDelete is included in Options.
Up
Moves to the previous row in the dataset. The currently selected column remains the same.
Down
Moves to the next row in the dataset. The currently selected column remains the same. Appends a new row when positioned at the end of the dataset and dgDiableInsert has not been included in Options.
Page Up
Moves towards the beginning of the dataset by the number of rows specified in VisibleRows.
Page Down
Moves towards the end of the dataset by the number of rows specified in VisibleRows.
Escape
Cancels an active editor for the selected cell. Clears pending modifications to the Field for the column.
Insert
Inserts a new row at the current row position when dgDisableInsert has not been included in Options. The actual position for the new row can change if the dataset has sorting or ordering capabilities.
Home
Changes the selected cell to first non-fixed column in the control. An active editor is removed.
Ctrl + Home
Moves to the first row in the dataset. An active editor is removed.
End
Changes the selected cell to the last visible column in the control. An active editor is removed.
Ctrl + End
Moves to the last row in the dataset. An active editor is removed.
Space
Toggles the value in a column which uses a checkbox editor.
Ctrl + Multiply (Num Pad *)
Toggles the selected state for the current row when dgMultiSelect is included in Options.

KeyDown reads and writes values in GridFlags as needed while handling cell editors and performing dataset navigation.

KeyDown calls the inherited KeyDown method to process keys not explicitly handled by the data-aware control.

KeyDown signals the OnKeyDown event handler when it has been assigned for the control.

LinkActive updates the control after a change to the state of its DataLink

LinkActive is a procedure which updates the control when the state of its DataLink is changing. Value contains False when the dataset for the DataLink will be closed. The state change causes updates to other control properties like SelectedRows, and the KeyBookmark which tracks the selected row in the linked dataset. LinkActive calls RemoveAutomaticColumns to remove automatic columns added to the control when the DataLink became active. The LayoutChanged method is called to refresh the control after updates to the Columns property.

No actions are performed in the method when Value contains True.

True when the dataset is open LayoutChanged links columns to Fields and inserts any required automatic columns

LayoutChanged is a virtual procedure used to link Columns to the Fields which read and write the values used in the control. LayoutChanged calls the TDBGridColumns.LinkFields method establish the column-to-field association. If Columns have not been explicitly defined the AddAutomaticColumns method is called to add a column for each Field in the linked dataset.

LayoutChanged calls the BeginLayout and EndLayout methods to minimize the number of times the OnLayoutChange event is signalled during updates to the control.

LayoutChanged performs no actions when ComponentState indicates the control is being destroyed (contains csDestroying).

Performs layout operations after the control is loaded at run-time

Loaded performs the notification that signals component streaming has been completed at run-time. Loaded calls the LayoutChanged method to update the visual appearance of the control. Loaded calls the inherited Loaded method

MoveSelection changes the current selection in the control

MoveSelection causes the current selection in the control to be changed. MoveSelection calls the inherited MoveSelection method. If the selection change causes a different column to become active, the OnColEnter event handler is signalled (when assigned). MoveSelection calls the UpdateActive method to ensure that the correct row and/or column are drawn in the control.

TCustomGrid.MoveSelection
MouseDown handles mouse down messages in the control and signals the OnMouseDown event handler

MouseDown handles mouse button clicks (when allowed) in the control. MouseDown ensures that the specified Button and State are correctly applied to the control similar to the processing provided in KeyDown method. MouseDown translates screen coordinates into the row and column numbers used in the control and performs actions needed for focus selection editing or navigation.

MouseDown signals the OnMouseDown event handler when assigned in the class instance.

Prepares the Canvas to render the specified cell with the drawing state in aState

PrepareCanvas prepares the Canvas used to render the cell at the specified position with the drawing state in aState. PrepareCanvas calls the inherited PrepareCanvas method and sets the brush color in the Canvas to the value need for fixed or focus/selected columns.

Gets the editor used for the SelectedField in the control

SelectEditor is a procedure used to get the editor used for the SelectedField in the control. SelectEditor requires an active dataset in DataLink to access properties and methods in SelectedField. SelectEditor uses SelectedField to get the maximum length of the Field in the dataset and stores the value in the Editor for the control.

SelectEditor calls the Inherited SelectEditor method to initialize the class used in the Editor property. SelectEditor signals the OnSelectEditor event handler (when assigned) to get a custom value for the Editor property. Please note that Editor is set to Nil if the OnSelectEditor event handler is not assigned for the control.

Sets the textual value for the editor in the specified cell

SetEditText sets the textual value for the editor in the specified cell.

UpdateActive redraws the control when the active row in the dataset is changed

UpdateActive forces the control to be redrawn when the active row in the linked dataset is changed. UpdateActive requires an active dataset in DataLink with a selected record. No actions are performed in the method when the dataset is closed or contains no rows. UpdateActive calls InvalidateCell when the selected row in the control has changed. InvaidateRow is called to update the selected row in the control.

Gets the total number of visible columns (or fields) in the grid

UpdateGridCounts is an Integer function which gets the total number of visible columns (or fields) in the grid control.

UpdateGridCounts calls GetColumnCount to get the number of entries in the Columns collection. When Columns have been defined, and DataLink is Active, the RecCount and RowCount variables are updated. The UpdateGridColumnSizes method is used to adjust the sizes for the columns. If the linked dataset is Active, and a Row is Selected, the AdjustEditorBounds method is called.

Columns provides access to columns defined for the database grid control

Columns is a TDBGridColumns property that provides access to columns defined for the database grid control. Items in the Columns collection are represented as TColumn instances and can be explicitly created in the IDE at design-time, or automatically added when the OptionsExtra property includes the value dgeAutoColumns.

TDBGridColumns TColumn TDBGrid.OptionsExtra
Provides access to the dataset displayed in the grid

DataSource is a TDataSource property which provides access to the DataSet displayed in the database grid control. Read and write access to the property are redirected to the DataLink property.

Reading the value for DataSource returns the value stored in the TComponentDataLink instance.

Writing the value for DataSource sets the value in the TComponentDataLink instance (when they are not the same). Write access to DataSource also resets the width of columns in the grid by calling RenewColWidths. UpdateActive is called to redraw the grid control after changes to the DataSource and Columns properties.

Enables or disables optional features or behaviors in the grid control

Options is a TDBGridOptions property that specifies features or behaviors that can be enabled or disabled by values stored in the property. Please note that these options are different than the TGridOption values used in the ancestor class. Options can contain zero (0) or more values from the TDBGridOption enumeration.

Options contains the following default values when the control is created:

  • dgColumnResize
  • dgColumnMove
  • dgTitles
  • dgIndicator
  • dgRowLines
  • dgColLines
  • dgConfirmDelete
  • dgCancelOnExit
  • dgTabs
  • dgEditing
  • dgAlwaysShowSelection

See TDBGridOption for more information about values in the enumeration and their meanings.

Changing value(s) in Options causes other aspects of the grid control to be updated to reflect change(s) to the property. ChangedOptions is updated to reflect the enumeration values added or removed in the request. Some enumeration values force other features or behaviors to be disabled. For instance: row selection. Enabling row selection forces the options for editing, always displaying the editor, and row highlighting to be removed from the Options property. Finally, removing multi-selection from the Options property forces the SelectedRows and KeyBookmark properties to be cleared.

The TDBGridOption values stored in Options are different than the TGridOption values used in the ancestor class. As a result, SetOptions (the write access specifier) must translate any TDBGridOption values to their TGridOption equivalents and store them in the inherited Options property. Welcome to the dark world of inheritance in visual controls. It's tedious... just look at the code.

Indicates if modifications are allowed in the grid control

ReadOnly is a Boolean property that indicates if modifications are allowed in the grid control. Please note that ReadOnly applies to the visual grid control only. It does not take into account whether Fields in Columns or the DataSet in DataSource allows modifications.

Event handler for mouse click in a column for the grid

OnCellClick is a TDBGridClickEvent property that contains the event handler signalled when a mouse button is clicked in a cell for the grid control. Assign a procedure to the OnCellClick property to respond to mouse click messages in a column for the grid control.

OnCellClick is used the implementation of the CellClick method.

Event handler signalled when the mouse enters a column

OnColEnter is a TNotifyEvent property that implements the event handler signalled when the mouse enters a column for the grid control. OnColEnter is also signalled when the grid control gains focus. Assign a procedure to the property to allow responding to the notification event.

OnColEnter is triggered from the MoveSelection method.

Event handler signalled when the mouse exits a column

OnColExit is a TNotifyEvent property that implements the event handler signalled when the mouse exits a column in the grid control. OnColExit is also signalled when the grid control loses focus. Assign a procedure to the property to allow responding to the notification event.

OnColExit is triggered from the BeforeMoveSelection method.

Event handler signalled when the order of a column is changed

OnColumnMoved is a TMovedEvent property that implements an event handler signalled when the order of a column in the grid control is changed. Assign a procedure to the event handler to respond to the event notification. OnColumnMoved is triggered from the ColRowMoved method after the new column ordering has been applied.

Use OnRowMoved to responding to row ordering notification events.

Event handler signalled when a cell title needs to be drawn

OnDrawColumnTitle is a TDrawColumnCellEvent property that implements the event handler signalled when a cell title in the control needs to be drawn. Assign a procedure to the event handler to perform drawing needed for the cell title using the arguments to the routine.

TDrawColumnCellEvent
Event handler signalled when a cell needs to be drawn

OnDrawColumnCell is a TDrawColumnCellEvent property that implements the event handler signalled when a cell in the control needs to be drawn. Assign a procedure to the event handler to perform drawing needed for the cell using the arguments to the routine.

OnDrawColumnCell is triggered from the DrawCell method after the Canvas is prepared and any fixed cell or DefaultDrawing is performed. Please note that OnDrawColumnCell is not performed at design-time, or for fixed rows in the grid control.

TDrawColumnCellEvent
Event handler signalled to get the edit mask for a Field

OnFieldEditMask is a TGetDbEditMaskEvent property that implements the event handler signalled to get the edit mask used for a Field in the grid control. OnFieldEditMask allows overriding the edit mask assigned to a Field in the Columns property, or assigning an edit mask for Fields that do not already have one. Assign a procedure to the event handler to respond to the event notification.

OnFieldEditMask is triggered from the GetEditMask method when the DataSet in DataLink is active.

Event handler for mouse clicks on a Title cell

OnTitleClick is a TDBGridClickEvent property that implements the event handler signalled when a mouse click occurs in the fixed title cell for a column. Use OnTitleClick to perform actions required when the title cell for a column is clicked. Assign a procedure to the event handler to respond to the event notification.

OnTitleClick is triggered from the DoHeaderClick method.

Create is the constructor for the TCustomDBGrid instance. Create calls the inherited Create method, and allocates resources for properties in the class instance. Create sets the default event handlers used in DataLink to the corresponding procedures in the class:

  • OnDataSetChanged
  • OnDataSetClose
  • OnDataSetOpen
  • OnDataSetScrolled
  • OnEditingChanged
  • OnFocusControl
  • OnInvalidDataset
  • OnInvalidDataSource
  • OnLayoutChanged
  • OnRecordChanged
  • OnUpdateData

Create calls RenewColWidths to set columns to their default widths and to disable column auto-sizing.

Create sets the values in the Options property to establish the baseline features and behavior enabled for the grid control, including:

  • dgColumnResize
  • dgColumnMove
  • dgTitles
  • dgIndicator
  • dgRowLines
  • dgColLines
  • dgConfirmDelete
  • dgCancelOnExit
  • dgTabs
  • dgEditing
  • dgAlwaysShowSelection

See the Options property and TDBGridOption type for more information on values in the enumeration.

Values in the Options property from the ancestor class are also updated. They use the set of enumeration values in TGridOption, and are updated to include values which correspond to the TDBGridOption values used in the database grid control.

Create sets the default values in the ExtraOptions property to the following:

  • dgeAutoColumns
  • dgeCheckboxColumn

The value of the AutoAdvance property is set to aaRightDown, indicating the cell navigation is from left-to-right and then top-to-bottom in the grid control.

Create sets the value in ScrollBars to ssBoth indicating that both horizontal and vertical scroll bars are needed, and sets AllowOutboundEvents to False to prevent forwarding of event notifications to the ancestor class.

TCustomGrid.Create
Owner of the component Default method used for drawing cells in a column

DefaultDrawColumnCell is the default method used for drawing cells in a column. DefaultDrawColumnCell uses the specified column to get the Field and the editor style needed to render the cell.

Checkbox columns are drawn by calling the DrawCheckBoxBitmaps method. Other editor styles use the DisplayText for the TField as the value drawn using the DrawCellText method. Please note that Fields with a data type of ftBlob are always rendered as the string literal '(blob)'.

Use the OnDrawColumnCell event handler to render a cell when DefaultDrawing is not enabled for the grid control.

Canvas rectangle for the cell Index of the Field for cell data Column definition for the cell Grid drawing state for the cell Destroy is the destructor for TCustomDbGrid

Destroy is the overridden destructor in TCustomDbGrid. Destroy frees any bookmarks stored in the SelectedRows property. Destroys ensures that event handlers assigned to its DataLink property are removed prior to freeing resources allocated to the property.

Destroy calls the inherited Destroy method.

TCustomGrid.Destroy TCustomDBGrid.DataLink TCustomDBGrid.SelectedRows
Field that reads and writes data for the currently selected column

SelectedField is a TField property with the Field used to read and write data for the selected column in the grid control. SelectedField is updated when column navigation occurs in the control.

GetCurrentField is the read access specifier for the property, and returns the TField instance derived by GetFieldFromGridColumn for the selected column. SetCurrentField is the write access specifier for the property, and stores the new Field value as the selected column. No action is performed if the new Field value is the same as the current value for the property.

SelectedField is used in the implementation of various method in the control, such as: KeyDown, SelectEditor, UpdateData, and SwapCheckBox.

Use SelectedColumn to get the TColumn instance for the currently selected cell in the grid control.

Clears the data display area for the grid control

EmptyGrid is a procedure used to clear the data content for the grid control. EmptyGrid calls the Clear method to remove the visual display for data in the grid control. Please note that stored data is not removed; only the visual display for the control is affected. EmptyGrid ensures that fixed display columns are retained. EmptyGrid also resets the width of the row indicator to its default value when dgIndicator is included in the Options for the control.

EmptyGrid is used in the implementation of the DoLayoutChanged method.

Read access specifier for the SelectedColumn property

GetCurrentColumn is a TColumn function used as the read access specifier for the SelectedColumn property. GetCurrentColumn checks the Columns property to ensure that it is enabled for the control. The return value is the TColumn instance stored at SelectedIndex in Columns when Enabled. The return value is Nil if Columns has not been enabled for the control.

Use SelectedColumn to get the currently selected column in the grid control. Use SelectedField to the TField which reads and writes data for the currently selected column in the grid control.

Read access specifier for the SelectedIndex property

GetSelectedIndex is an Integer function used as the read access specifier for the SelectedIndex property. GetSelectedIndex returns the ordinal position of the currently selected column in the Columns property. If Columns has not been Enabled for the control, the ordinal position of the Field for the currently selected column is returned.

Use SelectedIndex to read or write values for the property.

Ordinal position of the currently selected column Write access specifier for the ExtraOptions property

SetExtraOptions is a procedure used as the write access specifier for the ExtraOptions property. SetExtraOptions ensures that new TDBGridExtraOption values in AValue are properly applied to the grid control. This includes repainting the control when Checkbox columns are enabled or disabled, and when adding or removing the automatic columns option. SetExtraOptions calls UpdateActive when automatic columns have been added or removed.

Use ExtraOptions to read or write values in the property.

New value for the ExtraOptions property Write access specifier for the SelectedIndex property

SetSelectedIndex is a procedure used as the write access specifier for the SelectedIndex property. SetSelectedIndex updates the ordinal position of the currently selected column to the specified value.

Use SelectedIndex to read or write values for the property.

New value for the SelectedIndex property Indicates the DataLink contains a valid and active Dataset

ValidDataSet is a Boolean function used to indicate if the DataLink for the control contains a valid and active Dataset. The return value is True when DataLink has a Dataset assigned to the property, and it has been marked as Active.

ValidDataSet is used in the implementation of various methods including KeyDown, MouseDown, and DoExit.

True when the control points to a valid dataset Indicates if the dataset can cancel an active insert

InsertCancelable is a Boolean function that indicates if the dataset for the control can cancel an active insert operation. InsertCancelable uses the DataSet in DataLink to ensure that the State contains dsInsert. The return value is False if DataSet state has any value other than dsInsert. InsertCancelable also examines both DataSet and DataLink to see if either of their Modified properties has been set. The return value is False when either has been modified.

InsertCancelable is used in the implementation of methods like KeyDown, MouseDown, and DoExit.

True when the insert can be cancelled Prepares the grid control for updates to its display area

StartUpdating is a procedure used to prepare the grid control for updates to its display area. StartUpdating checks the value from UpdatingData to see if the procedure has already been called. No actions are performed in the method when UpdatingData returns True.

StartUpdating updates the GridStatus property to include the value gsUpdatingData. The value in the ControlStyle property is also updated to include the value csActionClient. Finally, the LockEditor method is called to prevent changes in the editor control while the update is in progress.

StartUpdating and EndUpdating are used in the implementation of the UpdateData method to prevent multiple calls to UpdateData.

Restores the status of the control after updating its display area

EndUpdating is a procedure used to restore the status of the control after an update to its display area. EndUpdating ensures that the value gsUpdatingData is removed from the GridStatus property, and restores the value in ControlStyle to its value prior to starting the update; the value csActionClient is removed from the property. The UnLockEditor method is called to re-enable an editor control in the grid.

StartUpdating and EndUpdating are used in the implementation of the UpdateData method to prevent multiple calls to UpdateData.

Indicates if UpdateData has already been called for the control

UpdatingData is a Boolean function that indicates if the UpdateData method has already been called for the grid control. UpdatingData returns True if the GridStatus property contains the value gsUpdatingData. The GridStatus value is added in the StartUpdating method. UpdatingData prevents multiple calls to UpdateData.

True when UpdateData has been called for the control Toggles the bookmark in SelectedRows for the current grid row

ToggleSelectedRow is a procedure used add or remove the bookmark for the current row in the SelectedRows property. ToggleSelectedRow calls the SelectRecord method to toggle the value in SelectRows using its CurrentRowSelected property. ToggleSelectedRow is used in the KeyDown or MouseDown methods when Ctrl + Multiply (Num Pad *) or Ctrl + MBLeft are pressed.

Changes the selection in the SelectedRows property

SelectRecord is a procedure used to change the SelectedRows.CurrentRowSelected property to the specified value. SelectRecord checks the Options property to see if the value dgMultiSelect is included, and updates SelectedRows.CurrentRowSelected. No action is performed in the method if Options does not include the value dgMultiSelect.

SelectRecord is used in the implementation of various methods such as: KeyDown, MouseDown, ToggleSelectedRow, and ClearSelection.

True when the current record should be selected Adjusts scrollbars using the record count and the visible rows for the control

GetScrollbarParams is a procedure used to adjust scrollbars using the record count for the dataset and the number of visible rows for the control.

Adds a column for each Field in the dataset

AddAutomaticColumns is a procedure used to add a column for each Field in the dataset.

Please note that AddAutomaticColumns can be performed at run-time only; no actions are performed in the method at design-time.

AddAutomaticColumns requires an active dataset to access the Fields that must be added to the grid control. No actions are performed if the dataset in DataLink has not been assigned or marked as Active.

AddAutomaticColumns cannot be performed when GridStatus contains either gsRemovingAutoColumns or gsLoadingGrid. No actions are performed in the method when these values are included in the GridStatus property.

AddAutomaticColumns is enabled by including the value dgeAutoColumns in the OptionsExtra property. No actions are performed in the method when the feature has not been included in the OptionsExtra property.

AddAutomaticColumns uses DataLink to get the Fields for the dataset, and checks the Columns collection to see if a column already exists for each Field. If the Field is already in the collection, it is skipped to avoid duplicate Fields. Missing Fields are added to Columns using its Add method, and sets the IsAutomaticColumn and Visible properties to True for each. When missing Fields have been added, the ResetColumnsOrder method in Columns is called using the coFieldIndexOrder column ordering option.

AddAutomaticColumns updates the GridStatus property prior to adding columns to include the value gsAddingAutoColumns. The value is removed from GridStatus when adding columns has completed. This prevents the TDBGridColumns.Add method from removing automatic columns while the add operation is still active.

See RemoveAutomaticColumns for information about removing automatic columns in the Columns collection.

InvalidateSizes renders the Sizes non-valid

InvalidateSizes is a procedure used to force the grid to recalculate column sizes and to repaint its display area. InvalidateSizes updates the GridFlags for the control to include the value gfVisualChange.

ColumnEditorStyle gets the button style for the column being edited

ColumnEditorStyle is a TColumnButtonStyle function used to get the button style for the specified column number or Field in the grid control. ColumnEditorStyle assumes the default button style is cbsAuto unless overridden by settings in the Columns collection or by the Field definition in the dataset.

ColumnEditorStyle calls ColumnFromGridColumn to get the TColumn instance for the specified column number. Its ButtonStyle property is used as the return value if Columns has been Enabled. Otherwise, DefaultEditorStyle is called for the specified TField to get the return value for the method. DefaultEditorStyle will use cbsCheckBoxColumn as the button style when dgeCheckboxColumn has been included in the OptionsExtra property.

ColumnEditorStyle is used in the implementation of various methods including: CellClick, DefaultDrawCell, DefaultDrawColumnCell, EditorByStyle, KeyDown and MouseDown.

Button style for the column or Field Handle mouse wheel down events in the grid control

DoMouseWheelDown is an overridden Boolean function used to handle mouse wheel down events in the grid control. The return value is True when the mouse wheel event has been handled in the method. DoMouseWheelDown signals the OnMouseWheelDown event handler when it has been assigned to handle the mouse event. If OnMouseWheelDown cannot handle the mouse event, and the DataLink is marked as Active, DataLink calls its MoveBy method.

TControl.DoMouseWheelDown
True when the mouse event is handled in the method Shift state for the mouse wheel event Location of the mouse wheel event Handle mouse wheelup events in the grid control

DoMouseWheelUp is an overridden Boolean function used to handle mouse wheel up events in the grid control. The return value is True when the mouse wheel event has been handled in the method. DoMouseWheelUp signals the OnMouseWheelUp event handler when it has been assigned to handle the mouse event. If OnMouseWheelUp cannot handle the mouse event, and the DataLink is marked as Active, DataLink calls its MoveBy method.

True when the mouse event is handled in the method Shift state for the mouse wheel event Location of the mouse wheel event Prepares the canvas and signals OnPrepareCanvas

DoPrepareCanvas is an overridden procedure used to prepare the Canvas to draw a cell in the grid control. DoPrepareCanvas applies to data cells and performs no actions in the method when aRow refers to a fixed row in the control. In addition, DoPrepareCanvas applies only when DefaultDrawing contains False. No actions are performed in the method when DefaultDrawing is enabled.

DoPrepareCanvas calls GetSelectedState to determine if the Canvas is updated with brush and font colors used to draw in a selected state. DoPrepareCanvas signals the OnPrepareCanvas event handler when it has been assigned for the control using the specified column number and drawing state.

TCustomGrid.DoPrepareCanvas
Column number for the operation Row number for the operation Drawing state for the operation Draws all data rows in grid control

DrawAllRows is an overridden procedure used to draw all data rows for the control. DrawAllRows checks the DataLink property to determine if a DataSet is available for the operation. When DataLink is marked as Active, its ActiveRecord is used to reposition the DataSet after the drawing operation is completed. DrawAllRows calls the inherited method, and restores the position of the DataSet prior to exiting from the method.

Draws a Checkbox bitmap for the specified Boolean column

DrawCheckboxBitmaps is a procedure used to draw the Checkbox bitmap for the specified column. DrawCheckboxBitmaps draws the checkbox bitmap only when the editor for the column is not visible; otherwise, no actions are performed in the method.

DrawCheckboxBitmaps examines the specified Field argument to ensure that it uses a Boolean data type. If the Field IsNull, the value cbGrayed is assigned to the aState argument. Otherwise, the TField.AsBoolean method is used to determine if aState is set to cbChecked or cbUnChecked. For Fields that do not use ftBoolean in the data type, the TField.AsString method is used to determine if the Field matches the value in TColumn.ValueChecked or TColumn.ValueUnChecked.

DrawCheckboxBitmaps signals the DrawCheckboxBitmaps event handler when it has been assigned in the control.

DrawCheckboxBitmaps calls the DrawGridCheckboxBitmaps method to render the Checkbox bitmap with the necessary drawing state.

Column number to draw Canvas rectangle for the operation Field with data for the column Draws the fixed text at the specified row and column numbers

DrawFixedText is a procedure used to draw a fixed (or caption) cell at the specified row and column numbers. DrawFixedText calls the DrawIndicator method for the active record when aCol contains 0 (zero) and Options includes the value dgIndicator. Otherwise, the DrawColumnText method is called using the arguments passed to the method.

DrawFixedText is used in the implementation for the DefaultDrawCell method.

Column number to draw Row number to draw Canvas rectangle for the drawing operation Drawing state for the operation Gets the number of rows to buffer in the grid control

GetBufferCount is a virtual Integer function used to get the number of rows to buffer for display in the grid control. The return value contains the number of rows that can be displayed using the DefaultRowHeight for the control. The return value is decreased by 1 when column titles are enabled in the Options property with the dgTitles enumeration value.

GetBufferCount is called from the UpdateBufferCount method.

Number of data rows visible in the grid control Gets the default alignment for the column

GetDefaultColumnAlignment is an overridden TAlignment function used to get the default alignment for data at the specified column number. GetDefaultColumnAlignment gets the TField for the specified column when assigned, and uses its Alignment property as the return value for the method. The value taLeftJustify is used when a TField cannot be found for the specified column number.

Default alignment for the column Column number to use from the dataset Gets the default width for the specified column

GetDefaultColumnWidth is an overridden Integer function used to get the default width for the specified column number. GetDefaultColumnWidth calls the DefaultFieldColWidth method for the specified column. The return value is the width of the column calculate using either the display name or the display width for the TField in the column.

Default width of the column Column number to use for the calculation Gets the default ReadOnlyvalue for the specified column

GetDefaultColumnReadOnly is an overridden Boolean function used to get the ReadOnly value for the grid control. GetDefaultColumnReadOnly determines the effective read only status for the control using the ReadOnly property, as well as the DataLink property and the TField used for the specified column.

True when the column cannot be modified Column number to examine Gets the default title displayed for the specified column

GetDefaultColumnTitle is an overridden String function used to get the default title displayed for the specified column number. GetDefaultColumnTitle gets the TField used for the column (when available) and uses its DisplayName as the return value for the method. The return value is an empty String ('') when a TField instance is not available for the specified column.

Default title for the column Column number to locate in the Fields for the grid control Get the default row height for records displayed in the grid

GetDefaultRowHeight is an overridden Integer function used to get the default row height for records displayed in the grid control. GetDefaultRowHeight calls the inherited GetDefaultRowHeight method to get the return value for the method. The calculated row height is decreased by 2 pixels to allow space for borders on the editors overlaid onto the grid control.

TCustomGrid.GetDefaultRowHeight
Default height for records displayed in the control Gets the bitmap displayed for a Checkbox at the specified location

GetImageForCheckBox is an overridden TBitmap function used to get the bitmap displayed for a Checkbox at the specified location in the grid control. GetImageForCheckBox calls the inherited GetImageForCheckBox method using the passed arguments to get the return value. GetImageForCheckBox signals the OnUserCheckboxBitmap event handler when it has been assigned in the control to allow overriding the TBitmap used for the desired TCheckboxState.

Bitmap to display for the Checkbox column Column number for the cell Row number for the cell Checkbox state for the column Images for the checkbox states Ordinal position for the image Bitmap for the checkbox Determines if the cell at the specified location is currently selected

GetIsCellSelected is an overridden Boolean function used to determine if the cell at the specified location is currently selected. GetIsCellSelected calls the inherited method to get the return value, and also examines the value in DrawingMultiSelRecord. The return value is True when the cell is either selected or multi-selected (when enabled).

True when the specified cell is selected or multi-selected Column number to examine Row number to examine Determines the visibility of horizontal and vertical scroll bars for the control

GetSBVisibility is an overridden procedure used to determine the visibility of horizontal and vertical scroll bars for the control. GetSBVisibility calls the inherited method to use the logic implemented in the ancestor class. GetSBVisibility overrides the value used for the vertical scroll bar; it is set to True when ScrollBars contains ssVertical or ssBoth. ScrollBarAutomatic is called when the vertical scroll bar is not visible, and the GetScrollbarParams method is used to update the vertical scrollbar settings.

Removes automatic columns added to the grid control

RemoveAutomaticColumns is a procedure used to remove automatic columns added to the grid control in the AddAutomaticColumns method. Automatic columns are generated at run-time when the value dgeAutoColumns is included in the OptionsExtra property. The feature cannot be enabled at design-time. No actions are performed in the method at design-time.

RemoveAutomaticColumns uses the Columns property to execute its RemoveAutoColumns method which removes the automatic columns in the collection.

RemoveAutomaticColumns is used in the implementation of the LinkActive and the SetExtraOptions methods.

Use the OptionsExtra property to control adding and removing automatic columns at run-time.

Stores status information about operations active for the grid control

GridStatus is a TDBGridStatus property which stores status information for the grid control. GridStatus is a set type that can contain 0 (zero) or more values from the TDbGridStatusItem enumeration, and indicate operations occurring in the control at run-time. Values in GridStatus are added and removed in several methods for the grid control to prevent duplicate calls the method while the operation is active.

See TDbGridStatusItem for more information about the values in the enumeration and their meanings.

Contains the extra options enabled for the grid control

OptionsExtra is a TDBGridExtraOptions property used to store extra options enabled for the grid control. OptionsExtra is a set data type which can contain 0 (zero) or more values from the TDBGridExtraOption enumeration. The default values in the property include dgeAutoColumns and dgeCheckboxColumn; these values enable the use of automatic columns for the linked dataset and displaying checkboxes for Boolean columns.

SetExtraOptions is the write access specifier for the property, and ensures that the grid control is updated to reflect values added to or removed from the set.

SelectedRows - recorded as a bookmark list

SelectedRows is a read-only TBookmarkList property used to store TBookmark instance for one or more rows selected in the grid control. SelectedRows will normally contain a single TBookmark entry in its Items property for a selected row. However, multiples entry can exist when multi-selection is enabled by including the value dgMultiSelect in the Options property.

SelectedRows is updated when methods which perform record navigation call the DrawRow, SelectRecord or ToggleSelectedRow methods.

Event handler signalled when a grid column has been resized

OnColumnSized is a TNotifyEvent property that implements the event handler signalled when a column has been resized. OnColumnSized allows the application to perform actions required after the column has been resized. Assign a procedure to the event handler to respond to the event notification.

OnColumnSized is triggered from the HeaderSized method when a change to a column width was requested.

Event handler signalled to prepare the grid canvas for drawing a cell

OnPrepareCanvas is a TPrepareDbGridCanvasEvent property that implements the event handler signalled to prepare the Canvas for drawing a cell in the grid. OnPrepareCanvas allows the application to provide custom settings in the Canvas for the Grid control. The Sender argument is the grid control, and can be used to access the Canvas or other properties in the component. Assign a procedure to the event handler to respond to the event notification.

OnPrepareCanvas is signalled from the DoPrepareCanvas method.

Grid to use for the operation Event handler signalled when the editor is selected for a Field in the grid

OnSelectEditor is a TDbGridSelEditorEvent property that implements the event handler signalled when an editor control is selected for the current Field in the grid. OnSelectEditor is used to modify or override the editor control for SelectedField in the grid control.

OnSelectEditor is signalled in the SelectEditor method after the default editor control has be chosen and its maximum length has been set. Assign a procedure to the event handler which modifies or assigns the control in the Editor argument.

Event handler signalled to get the image used for a checkbox entry on the grid

OnUserCheckboxBitmap is a property that implements the TDBGridCheckboxBitmapEvent event handler signalled to get the image used for a checkbox entry on the grid. OnUserCheckboxBitmap allows the application to override the TBitmap provided by the GetImageForCheckBox method. Assign a procedure to the event handler that implements the TDBGridCheckboxBitmapEvent interface to enable the event handler.

The user is encouraged to provide bitmaps to represent the three states for database grid checkboxes: gcbpUnChecked, gcbpChecked and gcbpGrayed.

Initiates the action associated with the grid control

InitiateAction is an overridden procedure used to initiate the action associated with the grid control. InitiateAction calls the inherited InitiateAction method. The EndUpdating method is called when GridStatus includes the value gsUpdatingData.

Gets an editor control with the specified button style

EditorByStyle is an overridden TWinControl function used to a get an editor control with the specified button style. EditorByStyle calls the ColumnEditorStyle method to get the button style for the current column and SelectedField. This allows the grid to override the cbsAuto button style when the SelectedField contains a Boolean data type. EditorByStyle calls the inherited method using the derived TColumnButtonStyle value as an argument. The editor control in the return value is supplied by the inherited EditorByStyle method.

Editor control for the specified button style Button style to use in the editor control Restores column widths to their default values

ResetColWidths is a procedure used to restore column widths in he grid to their default values. ResetColWidths uses the value in DefaultColWidths to determine if default column widths are already in use. When DefaultColWidths contains True, no actions are performed in the method.

ResetColWidths calls the RenewColWidths method to restore the column widths. The LayoutChanged method is called to refresh the grid control after the column layouts are altered.

Ordinal position of the selected column in the grid control

SelectedIndex is an Integer property that represents the ordinal position of the selected column in the grid control. The property value contains the result from ColumnIndexFromGridColumn when the Columns collection is enabled in the control. Otherwise, the value from FieldIndexFromGridColumn is used as the property value.

GetSelectedIndex is the read access specifier for the property value. SetSelectedIndex is the write access specifier for the property.

Represents the currently selected column in the grid control

SelectedColumn is a read-only TColumn property that represents the currently selected column in the grid control. SelectedColumn contains a value only when the Columns collection has been enabled (or contains visible columns) for the control. Otherwise, SelectedColumn returns the value Nil.

GetCurrentColumn is the read access specifier for the property value, and returns the TColumn instance in Columns at the position specified in SelectedIndex.

Implements an event handler signalled when a control gets focus

OnFocusControl is a procedure which implements the event handler signalled when a control gets focus in the database grid. It cannot be overridden. Use the OnFocusControl property in DataLink to override the event handler.

OnFocusControl ensures that SelectedField is updated with the specified Field and calls the SetFocus method. No actions are performed if CanFocus indicates the control cannot be focused, or a column is not found for the specified Field.

TFocusControlEvent TComponentDataLink
Field reference for the event Signals the OnMouseMove event handler for the grid control

MouseMove is an overridden procedure used to signal the OnMouseMove event handler for the grid control. MouseMove signals the OnMouseMove event handler when GridState contains the value gsSelecting, and the Dragging flag has not been set. Otherwise, the inherited MouseMove method is called in the method.

IsValidChar indicates if the specified Field contains the specified UTF-8 character

IsValidChar is a Boolean function that indicates if the Field specified in AField contains the UTF-8 encoded character in AChar. No action is required (or performed) when AChar contains a single byte character.

Please note that TField does not contain a method which verifies a Unicode character. This routine converts a multibyte Unicode character using UTF8ToSys and calls the TField.IsValidChar method to validate.

IsValidChar returns True when TField.IsValidChar returns the same or when AChar contains the BackSace (Decimal 8) character.

Data-aware grid control for display and editing rows and columns in a dataset

TDBGrid is a data-aware version of TStringGrid used to display and edit a Rows and Columns in a dataset.

TDBGrid inherits many of its properties from TCustomGrid and its immediate ancestor TCustomDBGrid.

HowToUseDataAwareControls HowToUseGrids
Area on the screen where various components are drawn

Canvas is a TCanvas that represents the area of screen on which the various components are drawn.

TCustomControl.Canvas
Indicates how the control is drawn relative to its parent

Align is a TAlignment property that indicates how the control is drawn relative to its parent . Align can be used to read or write the alignment instructions for the control. The control may have no alignment or custom client alignment, or can be aligned to the top, bottom, left or right of its parent control.

Determines how the control is to be anchored to its client or parent control

Either reads a flag containing the set of anchors to be used, or writes a set of anchors. If they have been written this is indicated in IsAnchorsStored.

Sets the auto advance option for the grid control AutoAdvance is a published property in TDBGrid which sets the option used in the grid control. The default value for the property is aaRightDown. A restricted set of options are available for the grid control: bsNone or bsSingle.

Refers to the physical columns of the grid displaying the contents of the relevant Fields.

The Columns property is configurable from the Object Inspector selecting the ellipsis (...) next to the property name in which case a pop-up memo box appears to allow editing. It deals with things like the size shape and format of the display and contains a link to the appropriate Field.

Do not confuse Grid columns (in the display) with the SQL usage of COLUMNS (Fields in our environment). The Fields consist of a series of cells arranged in Records which contain the actual data which are to be displayed and operated upon.

It is entirely possible that Fields in the dataset are not displayed, and the result is that Field order in a dataset may not correspond directly to the column order in a database grid; in fact the Columns property allows the user to configure which data Field is to be displayed in each column.

Sizing constraints for the control

Constraints is used to read or write values that determine the min and max values for the height and width of the control; reads the size constraints or stores new ones.

Default height for rows drawn in the grid control

DefaultRowHeight is an Integer property that contains the default height used for rows drawn in the grid control. If new rows of the grid are created by changing the RowCount property, the height of these new rows will be set to the value of the DefaultRowHeight property.

When the Options property includes the appropriate value, the row height may be changed at run-time.

Determines if the grid control is enabled for navigation and editing

Enabled is a published property in TDBGrid that determines if the control is available for editing and navigation. When Enabled contains False, the control usually appears 'greyed-out' or unavailable.

Use the Visible property to determine whether the control is displayed or hidden.

Controls whether the Hint is displayed for the control

Controls whether the value in the Hint property is shown when the mouse hovers over the control. If a value is stored for the property a storage flag is set.

Display of the actual hint is performed by the OnShowHint event handler.

Reads or writes boolean flag; default is False.

Use TabStop to allow or disallow access to the control using the Tab key.

If TabStop is True the control is in the tab order. If TabStop is False the control is not in the tab order and the user can't use the Tab key to move to the control.

Visible controls whether the grid control is visible

The Visible property controls the ability to see a visual control. If Visible is True the control is shown otherwise it is hidden. Calling Show sets among other properties Visible to True. Setting Visible to False is equivalent to calling Hide method.

The Visible property does not depend on control's parent visibility. Use IsVisible method to consider this and get real visibility.

Double-clicking is much more common in a Windows environment than in Unix or Linux where single-clicking is the default method for selecting an object. However, double-click is valid in all environments so a method should be supplied when appropriate.

Event handler signalled when a key is down while the control has focus

OnKeyDown is a TKeyEvent event handler signalled when a key is down while the control has focus. OnKeyDown is called from the KeyDown method when processing keys specific to the data-aware grid.

OnKeyDown differs from OnKeyPress. With OnKeyDown the key may have already been down when the control receives focus. With OnKeyPress the key needs to become pressed while the control has focus.

TDBGrid.OnKeyPress TDBGrid.OnKeyUp TKeyEvent

OnKeyPress is an event controller for a key being pressed while the control has focus.

OnKeyPress differs from OnKeyDown in that the key needs to become pressed while the control has focus; with OnKeyDown the key may have already been down when the control received focus.

OnKeyUp is an event handler for instance when a key is up (not pressed) while the control has focus

The key may already have been up when the control received focus or a pressed key may become released during the time the control has focus.