Example 2: A per-row action icon

Uses OnCellImageClick to turn a column’s ImageIndex icon into a per-row action button - deleting the current record - without a separate button column or component.

Scenario

A “trash can” icon in a narrow column, one per row. Clicking it deletes that record (after a confirmation), without also selecting the row the way an ordinary click on the column would (OnCellImageClick fires instead of OnCellClick, not alongside it - the one deliberate exception among this unit’s click events).

Setup

// FormCreate, after FGrid.Images is assigned:
ColActions.ImageIndex := IDX_TRASH;       // TEgColumn.ImageIndex - see TEgColumn
ColActions.FieldName := '';                // Custom Cell column, no field of its own
FGrid.OnCellImageClick := GridCellImageClick;

The handler

procedure TfrmOrders.GridCellImageClick(Column: TColumn);
begin
  if Column <> ColActions then Exit;  // only this one column has an action icon
  if MessageDlg('Delete this order?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
    Table.Delete;
end;

Why it works this way

Also available per column

TEgColumn.OnCellImageClick is the column-scoped equivalent - attach it directly to ColActions instead of checking Column <> ColActions in a grid-wide handler, if the action only ever applies to that one column:

ColActions.OnCellImageClick := ColActionsImageClick;

procedure TfrmOrders.ColActionsImageClick(Column: TColumn);
begin
  if MessageDlg('Delete this order?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
    Table.Delete;
end;

When both the grid-level and column-level handlers are assigned, the grid-level one runs first.

The same “instead of the native click” pattern for icons elsewhere in the grid: OnTitleImageClick for a column’s title image (this one does still let OnTitleCellClick fire alongside it - OnCellImageClick is the one exception), OnCornerImageClick for the fixed corner image, and OnBeforeDrawTitle to change which image a title shows, mirroring what OnBeforeDrawCell does for data-cell images.

See Also

(C) 2026 Easygate, Lda