[Overview][Constants][Types][Classes][Procedures and functions][Index] Reference for unit 'Grids' (#lcl)

TCustomGrid

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

TCustomGrid - the base class for all grid controls

Declaration

Source position: grids.pas line 570

type TCustomGrid = class(TCustomControl)

protected

  fGridState: TGridState;

  

  procedure AdjustEditorBounds(); virtual;

  procedure AutoAdjustColumn(); virtual;

  

AutoAdjustColumn - automatically adjust column properties to accommodate largest object

  procedure BeforeMoveSelection(); virtual;

  

Before move selection method.

  procedure CalcAutoSizeColumn(); dynamic;

  

  procedure CalcFocusRect();

  

  function CanEditShow; virtual;

  

  function CanGridAcceptKey(); dynamic;

  

  procedure CellClick(); virtual;

  

  procedure CheckLimits();

  

  procedure CheckLimitsWithError();

  

  procedure CMMouseLeave(); message;

  

  procedure ColRowDeleted(); dynamic;

  

  procedure ColRowExchanged(); dynamic;

  

  procedure ColRowInserted(); dynamic;

  

  procedure ColRowMoved(); dynamic;

  

  function ColRowToOffset();

  

  function ColumnIndexFromGridColumn();

  

  function ColumnFromGridColumn();

  

  procedure ColumnsChanged();

  

  procedure ColWidthsChanged; dynamic;

  

  function CreateColumns; virtual;

  

  procedure CheckNewCachedSizes(); virtual;

  

  procedure CreateWnd; override;

  

  procedure CreateParams(); override;

  

  procedure Click; override;

  

  procedure DblClick; override;

  

  procedure DefineProperties(); override;

  

  procedure DestroyHandle; override;

  

  function DoCompareCells(); dynamic;

  

DoCompareCells - perform the comparison of two or more cells in a grid

  procedure DoCopyToClipboard; virtual;

  

  procedure DoCutToClipboard; virtual;

  

  procedure DoEditorHide; virtual;

  

  procedure DoEditorShow; virtual;

  

  procedure DoExit; override;

  

  procedure DoEnter; override;

  

  function DoMouseWheelDown(); override;

  

  function DoMouseWheelUp(); override;

  

  procedure DoOnChangeBounds; override;

  

  procedure DoOPDeleteColRow();

  

  procedure DoOPExchangeColRow();

  

  procedure DoOPInsertColRow();

  

  procedure DoOPMoveColRow();

  

  procedure DoPasteFromClipboard; virtual;

  

  procedure DoPrepareCanvas(); virtual;

  

  procedure DoSetBounds(); override;

  

  function DoUTF8KeyPress(); override;

  procedure DrawBorder;

  

  procedure DrawAllRows; virtual;

  

  procedure DrawCell(); virtual;

  

  procedure DrawCellGrid(); virtual;

  

  procedure DrawCellText(); virtual;

  

  procedure DrawColRowMoving;

  

  procedure DrawColumnText(); virtual;

  

  procedure DrawEdges;

  

  procedure DrawFocusRect(); virtual;

  

  procedure DrawRow(); virtual;

  

  procedure EditButtonClicked();

  

  procedure EditordoGetValue; virtual;

  

  procedure EditordoSetValue; virtual;

  

  function EditorCanAcceptKey(); virtual;

  

  function EditorIsReadOnly; virtual;

  

  procedure EditorHide; virtual;

  

  function EditorLocked;

  

  procedure EditorSelectAll;

  

  procedure EditorShow(); virtual;

  

  procedure EditorShowInCell(); virtual;

  

  procedure EditorWidthChanged(); virtual;

  

  function FixedGrid;

  

  procedure FontChanged(); override;

  

  procedure GetAutoFillColumnInfo(); dynamic;

  

  function GetColumnAlignment();

  

  function GetColumnColor();

  

  function GetColumnFont();

  

  function GetColumnLayout();

  

  function GetColumnReadonly();

  

  function GetColumnTitle();

  

  function GetColumnWidth();

  

  function GetDeltaMoveNext(); virtual;

  

  function GetDefaultColumnAlignment(); virtual;

  

  function GetDefaultColumnWidth(); virtual;

  

  function GetDefaultColumnLayout(); virtual;

  

  function GetDefaultColumnReadOnly(); virtual;

  

  function GetDefaultColumnTitle(); virtual;

  

  function GetDefaultEditor();

  

  function GetDefaultRowHeight; virtual;

  

  function GetScrollBarPosition();

  

  procedure GetSBVisibility(); virtual;

  

  procedure GetSBRanges(); virtual;

  

  function GetEditMask(); dynamic;

  

  function GetEditText(); dynamic;

  

  function GetFixedcolor; virtual;

  

  function GetSelectedColor; virtual;

  

  function GridColumnFromColumnIndex();

  

  procedure HeaderClick(); dynamic;

  

  procedure HeaderSized(); dynamic;

  

  procedure InternalSetColCount();

  

  procedure InvalidateCell();

  

  procedure InvalidateRange();

  

  procedure InvalidateCol();

  

  procedure InvalidateFromCol();

  

  procedure InvalidateGrid;

  

  procedure InvalidateRow();

  

  procedure InvalidateFocused;

  

  function GetIsCellSelected(); virtual;

  

  procedure KeyDown(); override;

  

  procedure KeyUp(); override;

  

  procedure LoadContent(); virtual;

  

  procedure Loaded; override;

  

  procedure LockEditor;

  

  procedure MouseDown(); override;

  

  procedure MouseMove(); override;

  

  procedure MouseUp(); override;

  

  function MoveExtend();

  

  function MoveNextAuto();

  

  function MoveNextSelectable();

  

  procedure MoveSelection; virtual;

  

  function OffsetToColRow();

  

  procedure Paint; override;

  

  procedure PickListItemSelected();

  

  procedure PrepareCanvas(); virtual;

  

  procedure ResetEditor;

  

  procedure ResetOffset();

  

  procedure ResetSizes;

  

  procedure ResizeColumn();

  

  procedure ResizeRow();

  

  procedure RowHeightsChanged; dynamic;

  

  procedure SaveContent(); virtual;

  

  procedure ScrollBarRange();

  

  procedure ScrollBarPosition();

  

  function ScrollBarIsVisible();

  

  procedure ScrollBarPage();

  

  procedure ScrollBarShow();

  

ScrollBarShow method

  function ScrollBarAutomatic(); virtual;

  

ScrollBarAutomatic method

  procedure SelectEditor; virtual;

  

  function SelectCell(); virtual;

  

Is called if a grid cell is highlighted.

  procedure SetCanvasFont();

  

  procedure SetColor(); override;

  

  procedure SetColRow();

  

  procedure SetEditText(); dynamic;

  

  procedure SetBorderStyle(); override;

  

  procedure SetFixedcolor(); virtual;

  

  procedure SetSelectedColor(); virtual;

  

  procedure SizeChanged(); dynamic;

  

  procedure Sort(); virtual;

  

Sort method

  procedure TopLeftChanged; dynamic;

  

  function TryMoveSelection();

  

  procedure UnLockEditor;

  

  procedure UpdateHorzScrollBar(); virtual;

  

  procedure UpdateSelectionRange;

  

  procedure UpdateVertScrollbar(); virtual;

  

  procedure UpdateBorderStyle;

  

  procedure VisualChange; virtual;

  

  procedure WMHScroll(); message;

  

  procedure WMVScroll(); message;

  

  procedure WMKillFocus(); message;

  

  procedure WMSetFocus(); message;

  

  procedure WndProc(); override;

  

  property AllowOutboundEvents: Boolean; [rw]

  

AllowOutboundEvents - permits mouse click on an imaginary (out-of-bounds) cell; moves cursor to nearest valid cell

  property AlternateColor: TColor; [rws]

  

The colour to be used for the background on alternate rows of the grid. Having alternate rows in different colours can make the grid easier to read.

  property AutoAdvance: TAutoAdvance; [rw]

  

Automatically advance down the grid on successive mouse clicks or presses of the ENTER or TAB key

  property AutoEdit: Boolean; [rw]

  

Whether the Edit mode is automatically entered when a cell is selected

  property AutoFillColumns: Boolean; [rw]

  

Automatically fill columns with default values if nothing else specified

  property BorderStyle: TBorderStyle; [rw]

  

The available border styles for this sort of control

  property BorderColor: TColor; [rw]

  

The colour of the border for this control

  property Col: Integer; [rw]

  

Current column index.

  property ColCount: Integer; [rw]

  

Number of columns of the grid.

  property Columns: TGridColumns; [rws]

  

The properties of the columns in this grid

  property ColWidths: Integer; [rw]

  

Column widths for the grid.

  property DefaultColWidth: Integer; [rw]

  

Default value for the width of newly created grid columns.

  property DefaultRowHeight: Integer; [rws]

  

Default value for the height of newly created grid rows.

  property DefaultDrawing: Boolean; [rw]

  

Is the default drawing method to be used for this grid? Default is TRUE

  property DefaultTextStyle: TTextStyle; [rw]

  

Default style for displaying text - includes alignment, layout, single or multi-lines

  property DragDx: Integer; [rw]

  

  property Editor: TWinControl; [rw]

  

The editor to be used for modifying information in the cells of the grid

  property EditorBorderStyle: TBorderStyle; [rw]

  

The border style for the editor used in this grid

  property EditorMode: Boolean; [rw]

  

Is grid ready to accept edits? (EditorMode True)

  property EditorKey: Boolean; [rw]

  

  property EditorOptions: Integer; [rw]

  

The set of options available for the grid's editor

  property EditorShowing: Boolean; [rw]

  

Is the editor for the grid displayed?

  property ExtendedColSizing: Boolean; [rw]

  

  property ExtendedRowSizing: Boolean; [rw]

  

  property ExtendedSelect: Boolean; [rw]

  

ExtendedSelect - the ability to select cells beyond the boundary of the visible part of the grid

  property FastEditing: Boolean; [rw]

  

Is the FastEditing method being used?

  property AltColorStartNormal: Boolean; [rw]

  

AltColorStartNormal - using a second colour to display alternate rows, but starting the first row with the normal colour

  property FixedCols: Integer; [rw]

  

Number of the fixed columns of the grid (ie the columns containing title or identifier material, that don't get scrolled when the rest of the grid moves).

  property FixedRows: Integer; [rw]

  

Number of the fixed rows of the grid (ie the rows containing title or identifier material, that don't get scrolled when the rest of the grid moves).

  property FixedColor: TColor; [rw]

  

The color for the fixed cells of the grid.

  property FixedHotColor: TColor; [rw]

  

  property Flat: Boolean; [rw]

  

Is the cell to be displayed Flat, ie with no texturing or raised/lowered effect

  property FocusColor: TColor; [rw]

  

The colour to be used for the cell receiving focus

  property FocusRectVisible: Boolean; [rw]

  

FocusRectVisible - is the rectangle receiving focus visible?

  property GCache: TGridDataCache; [r]

  

  property GridFlags: TGridFlags; [rw]

  

  property GridHeight: Integer; [r]

  

  property GridLineColor: TColor; [rw]

  

Colour to be used for GridLines

  property GridLineStyle: TPenStyle; [rw]

  

Style to be used for GridLines

  property GridLineWidth: Integer; [rw]

  

Width (thickness) of GridLines

  property GridWidth: Integer; [r]

  

Width of the whole Grid

  property HeaderHotZones: TGridZoneSet; [rw]

  

  property HeaderPushZones: TGridZoneSet; [rw]

  

  property InplaceEditor: TWinControl; [r]

  

InplaceEditor - the editor to be used in-place, ie in the cell itself instead of outside the grid

  property IsCellSelected: Boolean; [r]

  

IsCellSelected - is the cell specified by aCol, aRow selected?

  property LeftCol: Integer; [rw]

  

LeftCol - the left-most column

  property Options: TGridOptions; [rw]

  

The options available for use in this grid

  property Row: Integer; [rw]

  

The current Row (record) within the grid

  property RowCount: Integer; [rw]

  

Number of rows in the grid

  property RowHeights: Integer; [rw]

  

The row heights for the grid.

  property SaveOptions: TSaveOptions; [rw]

  

The set of options for saving information from the grid (design, attributes, content or position)

  property SelectActive: Boolean; [rw]

  

  property SelectedColor: TColor; [rw]

  

Colour to be used for selected cells

  property SelectedColumn: TGridColumn; [r]

  

The column (field) currently selected

  property Selection: TGridRect; [rw]

  

The current selection (rows and columns) in the grid

  property ScrollBars: TScrollStyle; [rw]

  

The ScrollBars to be used with this grid

  property StrictSort: Boolean; [rw]

  

StrictSort - is strict sorting to be used?

  property TitleFont: TFont; [rw]

  

The font to be used in the grid's title

  property TitleStyle: TTitleStyle; [rw]

  

The style to be used for the grid's title

  property TopRow: Integer; [rw]

  

The first row (record) in the grid

  property UseXORFeatures: Boolean; [rw]

  

UseXORFeatures: When True, the dotted focus rectangle is painted using the XOR raster operation

  property VisibleColCount: Integer; [rs]

  

The number of visible columns

  property VisibleRowCount: Integer; [rs]

  

The number of visible rows

  property OnBeforeSelection: TOnSelectEvent; [rw]

  

  property OnCompareCells: TOnCompareCells; [rw]

  

Event handler for comparing the contents of grid cells

  property OnPrepareCanvas: TOnPrepareCanvasEvent; [rw]

  

Event handler to prepare the Canvas for drawing

  property OnDrawCell: TOnDrawCell; [rw]

  

Event handler for drawing a cell

  property OnEditButtonClick: TNotifyEvent; [rw]

  

Event handler for when the Edit button is clicked

  property OnPickListSelect: TNotifyEvent; [rw]

  

Event handler for selecting an item from a picklist (eg drop-down list in TComboBox)

  property OnSelection: TOnSelectEvent; [rw]

  

Event handler for when an area of a grid (one or a group of cells) is selected

  property OnSelectEditor: TSelectEditorEvent; [rw]

  

Event handler for selecting an editor

  property OnTopLeftChanged: TNotifyEvent; [rw]

  

Event handler when the top left cell is changed (ie the grid has been scrolled so that a different cell occupies top left)

public

  constructor Create(); override;

  

  destructor Destroy; override;

  

  procedure Invalidate; override;

  

  procedure EditingDone; override;

  

  procedure AutoAdjustColumns;

  

AutoAdjustColumns - automatically adjust the columns according to the size of their contents

  procedure BeginUpdate;

  

Begin updating the grid

  function CellRect();

  

The coordinates of the current cell (column, row) expressed as a standard rectangle (TRect)

  function CellToGridZone();

  

Convert the coordinates of the current cell (col, row) to a grid zone

  procedure CheckPosition;

  

Check the position of the cursor

  procedure Clear;

  

Clear all cells from the grid.

  function EditorByStyle(); virtual;

  

Select a cell editor control with the specified style

  procedure EditorKeyDown();

  

Emulate the OnKeyDown event handler in the cell editor

  procedure EditorKeyPress();

  

Emulate the OnKeyPress event handler in the cell editor

  procedure EditorKeyUp();

  

Emulate the OnKeyUp event handler in the cell editor

  procedure EndUpdate();

  

  procedure EraseBackground(); override;

  

Clear the background to the grid

  function IscellVisible();

  

Finds out whether a particular cell is visible

  procedure LoadFromFile();

  

Load the grid data from a file with the specified name

  function MouseCoord();

  

Find the mouse coordinates relative to the grid origin

  function MouseToCell();

  

  function MouseToLogcell();

  

Convert mouse coordinates to the position of a logical cell in the grid

  function MouseToGridZone();

  

  procedure SaveToFile();

  

Save the data in the grid to a file with specified name

  procedure SetFocus; override;

  

Set focus on the grid

  property SortOrder: TSortOrder; [rw]

  

Order of sorting - ascending or descending

  property TabStop;

end;

Inheritance

TCustomGrid

  

TCustomGrid - the base class for all grid controls

|

TCustomControl

  

TCustomControl - a base class for many window controls

|

TWinControl

  

The base class for all windowed controls

|

TControl

  

TControl - the main ancestor class for visual controls.

|

TLCLComponent

?

TObject

Description

A grid is a collection of cells that are organized in columns and rows. Grids are suitable for showing data that have tabular nature, for example tables in a database, or formulae and data in a spreadsheet.

Key properties:

The ColCount and RowCount properties contain the column and row count of the grid.

The FixedCols and FixedRows properties specify the count of fixed columns or rows that are used for headings.

The column widths and row heights of the grid are accessible with the ColWidths and RowHeights properties.

The DefaultColWidth and DefaultRowHeight properties are used to specify default column widths or row heights respectively.

The colors of the cells and the grid elements are specified with the AlternateColor, BorderColor, FixedColor, FixedHotColor, FocusColor, GridLineColor and SelectedColor properties. The GridWidth and GridHeight properties contain the dimension of the entire grid.

The ScrollBars property controls the creation of scrollbars for the grid.

The LeftCol, TopRow, VisibleColCount and VisibleRowCount properties contain information about the visible area of the grid.

The Options property controls options for the grid.

Key methods and events:

If the user highlights a cell of the grid, the SelectCell method is called that triggers the OnSelectCell event. The position of the highlighted cell is stored within the Col and Row property.

The MouseToCell method calculates a grid cell from a given screen position.

Huge changes to the grid should be encapsulated in calls to BeginUpdate and EndUpdate to speed up the application.

Component developers must override the DrawCell method in customized grids.

See also

TStringGrid

  

TStringGrid - a specialised grid for displaying strings (text material) in a matrix of columns and rows

TDrawGrid

  

TDrawGrid - a drawn grid. May contain images in its cells

HowToUseGrids

  

How to use Grids including StringGrids, DrawGrids and DbGrids

The latest version of this document can be found at lazarus-ccr.sourceforge.net.