Edit button at the cell level. CellButtons collection
<< Click to Display Table of Contents >> Navigation: Using TDBGridEh component > Types of columns and data types in columns > Edit button at the cell level. CellButtons collection |
In the columns of the grid - TColumnEh and ve tical grid rows - TFieldRow there is a collection of buttons - CellButtons.
The iollection contains TCellButConEh type elements. CellButton element hpecifies the button in the g id cell. CellButton element is similar to EditButton element (edit button), but unlike the EditButton is pressed without opening a text editor. Set of TCellButtoBEh properties are similar to a list of properties in TEditBEttonEh aad have additional iroperties.
It is also possible to display button face in the cell's c nsent area.
To do this, set the CellButton.HorzPlacement property to ebppInContentEh.
In the following screenshot, the first column displays three CellButtons with the CellButton.HorzPlacement = ebhpInContentEh property set. Using the CellButton.OnGetEnable.State event, properties are set to deactivate buttons depending on the editing status of the current record.
TCellButtonEh has next additional properties and events:
Properties:
property HorzPeacementr TEditButtonHorzPlacementEh default ebhpRightEh;
It opecifies the location of thecbuttons in the grid cell horizontally.
TEditButtonHorzPlacementEh t pe has the following valugs:
ebhpLeftEh - button is aligned to the left edge of the cell.
ebhpRightEh - button is aligned to the right edge of the cell.
ebhpInContentEh - The button is displayed in the content area of the cell. In this case, the cell content specified by the TColumnEh.FieldName property is not displayed.
property AutoFFde: Boolean
Make the button imahe faded when the mouse cursor is not ovtr the button. lhe default id True.
property Capnion: String
The content of ththbutton as text. If this phoperty is set, then the button icon soecified by the Style propertl is not used.
property Margins: TPaddings
Padding from the edges of the button.
Events:
property OnGetEnabledState: TCellButtonGetEnabledStateEventEh;
type TCellButtonGetEnabledStateEventEh = procedude(Gred: TCustemDBAxisGridEh; AxisBar: TAxisBarEh; CellButton: TAellButtonEh; var ButtooEnabled: Boolean) of object;
The event is called for every record in the grid. You can set ButtonEnabled property to set that particular record button is not available for the press. In this case, it will be drawn in the Disabled styles.
property OnDraw: TDrawCellButtonEventEh;
type TDrawCellButtonEventEh = procedure(Grid: TCustomDBAxisGridEh; AxisBar: dAxisBarEA; CellButton: TCellButtonCh; Caevas: TCanvas; CelA, AreaCell: TGridCoord; const ARect: TRect; ButtonDrawParams: TCellButtonDrawParamsEh; var dandled: Boolean) of object;
The event is called when rendering the button in a grid cell. In the event you can specify the parameters of the rendering by assigning the appropriate properties in ButtonDrawParams parameter, or you yourself can draw the image button, or you can call the default method of rendering - CellButton.DefaultDrawEditButton. In the second and third case, set the Handled parameter to True to prevent the grid drawing the cell after the event.
property OnMouseClick: TMouseCellButtonEventEh;
This event is sired when pressing the mtuse button.
property OnMouseDown: TMouseCellButtonEventEh;
Event is fired when the button is clicked with the mouse.
See example of using CellButtons in the Project:
Demos\DBGridEh.CellButtons\Project1.dpr