46
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
92 | Page
TAdvStringGrid miscellaneous display control
Showing active cell in fixed cells
With the property ActiveCellShow set true, it is possible to indicate the fixed row and column cell
for column and row where the focus cell is found, in a different color and different font. The
background color of the fixed cell is set with ActiveCellColor, the font is set with the ActiveCellFont
property. For normal display, the fixed cell uses the FixedColor background color and FixedFont for
text.
Note: when active cell display is activated and multiple fixed columns or fixed rows are shown in
the grid, the active cells are displayed on the innermost fixed columns/rows.
Background gradient or bitmap
TAdvStringGrid can show a bitmap or gradient as background in fixed cells only, normal cells only or
for all cells. The background bitmap is set with the grid.BackGround.Bitmap property. The selection
for which cells the background should be displayed is set with grid.BackGround.Cells. This
background bitmap can be tiled (grid.BackGround.Display = bdTile) or displayed at a fixed
(grid.BackGround.Display = bdFixed) position (set with grid.BackGround.Top and
grid.BackGround.Left)
To show a background gradient, set grid.Background.Display to bdGradientVert or bdGradientHorz
and select gradient start and end color with grid.Background.Color and grid.Background.ColorTo.
Bands
Banding of alternate colors is enabled in TAdvStringGrid with setting grid.Bands.Active = True.
The alternating colors are set with grid.Bands.PrimaryColor and grid.Bands.SecondaryColor. The
number of rows to display in primary color is set with grid.Bands.PrimaryLength, the number of rows
to display in secondary color is set with grid.Bands.SecondaryLength. Finally, it can be selected
whether the banding should be printed or not with the grid.Bands.Print property.
Note: when using a descendent class such as TAdvColumnGrid or TDBAdvGrid, it is required to set
the property ShowBands = true for the columns where bands should be displayed.
Control look
Various settings are combined here that control how inplace controls look in the grid. The
ControlLook property has following subproperties:
ButtonPrefix: Boolean;
When true, a & character is treated as shortcut prefix
and makes the next letter shortcut character that is
displayed underlined. When ButtonPrefix = false, the
& character is displayed literally in the button
control.
CheckAlwaysActive: Boolean;
When true, a checkbox is always displayed as active,
irrespective of the readonly state of the cell
CheckedGlyph: TBitmap;
Sets the glyph for a custom checked checkbox
CheckSize: Integer;
Sets the size of a checkbox
58
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
93 | Page
Color: TColor;
Sets the color for Borland style checkbox and
radiobuttons
CommentColor: TColor;
Sets the default comment triangle indicator color
ControlStyle: TControlStyle;
See below
DropDownAlwaysVisible: Boolean;
When true, the combobox dropdown button is always
displayed, irrespective of the editing mode
DropDownCount: integer;
Sets the nr. of items displayed in the dropdown of
inplace combobox editors
FixedDropDownButton: Boolean;
When true, a fixed cell has an additional right side
dropdown button when the mouse hovers the cell
FixedGradient*: TColor;
Series of properties that control the top & bottom
gradient of the fixed cell in normal, hot & down
state.
FlatButton: Boolean;
When true, inplace buttons are displayed in flat style
NoDisabledButtonLook: Boolean;
By default, buttons added in the grid in read only
cells are shown as disabled. To override this, set this
property to true.
NoDisabledCheckRadioLook: Boolean
By default, checkboxes and radiobuttons added in the
grid in read only cells are shown as disabled. To
override this, set this property to true.
ProgressBorderColor: TColor;
Sets the color of a progress bar border
ProgressMarginX: Integer;
Horizontal margin on left and right for the
progressbar in a cell
ProgressMarginY: Integer;
Vertical margin on top and below for the progressbar
in a cell
ProgressXP: Boolean;
When true, the progressbar is drawn with the
Windows XP visual style
RadioAlwaysActive: Boolean;
When true, a radiobutton is always displayed as
active, irrespective of the readonly state of the cell
RadioOffGlyph: TBitmap;
Sets the glyph for a custom unchecked radiobutton
RadioOnGlyph: TBitmap;
Sets the glyph for a custom checked radiobutton
RadioSize: Integer;
Sets the size of a radiobutton
SpinButtonsAlwaysVisible: Boolean;
When true, buttons of spin editor inplace editors are
always visible, irrespective of the editing state of a
cell.
46
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
94 | Page
UnCheckedGlyph: TBitmap;
Sets the glyph for a custom unchecked checkbox
The ControlStyle can have following values:
TControlStyle = (csClassic,csFlat,csWinXP,csBorland,csTMS,csGlyph,csTheme);
With:
csBorland
Borland style checkboxes and radiobuttons
csClassic
Normal Windows control look
csFlat
Flat control look
csGlyph
Use glyphs defined in ControlLook for checkboxes and radiobuttons
csTheme
Use Windows theme API (available in Windows XP or later) to draw checkboxes,
radiobuttons, buttons, …
csTMS
TMS style checkboxes and radiobuttons
csWinXP
Fixed Luna style control look (works on all Windows versions)
Row indicator
With the property grid.RowIndicator: TBitmap a bitmap can be set that is shown in the first fixed
column for the active row. A small arrow bitmap can be set for example to show the active row in a
similar way as the DB cursor is shown in a DB grid.
Global cell text appearance settings
Several grid properties affect global look of cell text which are:
AutoNumAlign When true, automatically selects right alignment for cells containing numeric data
only
EnhTextSize
When true, text that does not fit in the grid cell is displayed with end ellipsis
MultiLineCells When true, cell text containing line feeds is displayed on multiple lines
URLFull
When true, the protocol specifier is displayed along with the hyperlink, otherwise
it is used internally but not displayed
URLShow
When true, cell text starting with protocol specifiers http://, ftp://, nntp://,
mailto: is displayed in the URLColor and underlined
URLShowInText When true, any hyperlink of the type http://, http://, ftp://, nntp://, mailto:
that occurs in the text of a cell is displayed in the URLColor and underlined and
will act as a hyperlink when clicked. This means that if the cell content is “Visit
http://www.tmssoftware.com for details”, the hyperlink will be automatically
underlined without any need to write HTML <A> tags. This is different from using
51
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
95 | Page
just URLShow = true, where the entire cell text is treated as hyperlink or not.
WordWrap
When true, cell text is wordwrapped. This can be dynamically set for individual
cells by using the event OnGetWordWrap. Note that when WordWrap is enabled,
text in the cell is always vertically top aligned. The Windows wordwrap text
drawing API can only display wordwrapped text top aligned.
Cell selection
By default, selected cells are displayed in the clHighLight background color and clHightLightText
font color. Set grid.ShowSelection = false if the grid should not display selected cells. Settings that
control display of selected cells are:
SelectionColor: TColor;
Sets the background color of selected cells
SelectionColorTo: TColor;
When different from clNone, sets the gradient end color of a
selected cell.
SelectionColorMixer: boolean;
When true, the color of a selected cell is X% of color value of the
cell and 100-X% of the selectioncolor. X is the
SelectionColorMixerFactor and defaults to 50.
SelectionColorMixerFactor:
integer;
Selects the ratio of the color mixer between cell color and
selection color.
SelectionMirrorColor: TColor;
When different from clNone, sets the bottom gradient start color
of a selected cell.
SelectionMirrorColorTo: TColor; When different from clNone, sets the bottom gradient end color
of a selected cell.
SelectionRectangle: Boolean;
When true, a wide border rectangle is displayed around selected
cells
SelectionResizer: Boolean;
When true, the selection rectangle is displayed with rectangular
grip in bottom right corner to resize the selection
SelectionRTFKeep: Boolean;
When true, RTF text colors are not affected by selection text
color in selected cells
SelectionTextColor: TColor;
Sets the text color of selected cells
ShowSelection: Boolean;
When true, selected cells are displayed in SelectionColor and
SelectionTextColor
The selection in the grid can be hidden temporarily by the method grid.HideSelection and unhidden
later with grid.UnHideSelection.
Note: by default, when the SelectionTextColor is set to a color different from clNone, the
SelectionTextColor has priority over the font color of the cell itself. This is to ensure that for the
combination SelectionColor/SelectionTextColor, the cell text is always guaranteed to be visible. If it
33
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
96 | Page
is not desirable that the selection text color is different from the cell font color, set
grid.SelectionTextColor to clNone. With this setting, the cell text color will be always used.
Advanced topic: Smart cell resizing
With SelectionResizer and SelectionRectangle set true, the selection can be resized by dragging the
bottom left corner. If the property grid.Navigation.AllowSmartClipboard is set true as well, the
resizing of the selection will cause the smart clipboard operation to try to fill the new selection
based on the information found in the first selected cells. It will try to guess the data format of the
cells of the original selection and try to find the delta between 2 or more cells of the original
selection and apply this delta for completion for the new selection.
Example: original selection
Resized to new selection
Hilighting and marking errors in cells
With the <HI> tag and <E> tag an arbitrary part of the text can be highlighted or underlined with
error lines. TAdvStringGrid has a range of methods that allow to automatically highlight or
unhighlight text in cells or mark or unmark text in cells. The following set of methods is available
for this:
function HilightText(DoCase: Boolean; S,Text: string):string;
function UnHilightText(S:string):string;
procedure HilightInCell(DoCase: Boolean; Col,Row: Integer; HiText: string);
procedure HilightInCol(DoFixed,DoCase: Boolean; Col: Integer; HiText:
string);
procedure HilightInRow(DoFixed,DoCase: Boolean; Row: Integer; HiText:
string);
procedure HilightInGrid(DoFixed,DoCase: Boolean; HiText: string);
procedure UnHilightInCell(Col,Row: Integer);
procedure UnHilightInCol(DoFixed: Boolean; Col: Integer);
procedure UnHilightInRow(DoFixed: Boolean; Row: Integer);
procedure UnHilightInGrid(DoFixed: Boolean);
function MarkText(DoCase: Boolean; S,Text: string):string;
40
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
97 | Page
function UnMarkText(S:string):string;
procedure MarkInCell(DoCase: Boolean; Col,Row: Integer; HiText: string);
procedure MarkInCol(DoFixed,DoCase: Boolean; Col: Integer; HiText: string);
procedure MarkInRow(DoFixed,DoCase: Boolean; Row: Integer; HiText: string);
procedure MarkInGrid(DoFixed,DoCase: Boolean; HiText: string);
procedure UnMarkInCell(Col,Row: Integer);
procedure UnMarkInCol(DoFixed: Boolean; Col: Integer);
procedure UnMarkInRow(DoFixed: Boolean; Row: Integer);
procedure UnMarkInGrid(DoFixed: Boolean);
procedure RemoveMarker(ACol,ARow: Integer);
procedure RemoveAllMarkers;
Example: highlighting TMS in a cell
Grid.Cells[2,3] := ‘This is TMS software’;
Grid.HilightInCell(False,2,3,’TMS’);
This will display the cell as :
This is TMS software
Later the highlighting can be removed by calling grid.UnHiLightInGrid(False). This will remove
highlighting in any cell of the grid.
Trimming cells
Following functions are defined to perform trimming of values in a rectangle of grid cells, in a row,
in a column or in the entire grid:
procedure TrimRect(ACol1,ARow1,ACol2,ARow2: Integer);
procedure TrimCol(ACol: Integer);
procedure TrimRow(ARow: Integer);
procedure TrimAll;
Automatic sizing and numbering of columns and rows
TAdvStringGrid has several built-in methods to let the grid automatically adapt the column width or
row height to fit the text of cells.
Methods:
procedure AutoSizeCol(Col: integer);
Adapts the width of column Col to have all text in cells in this column fit.
procedure AutoSizeColumns(DoFixedCols: Boolean; Padding: integer);
Adapts the width of all columns (including fixed columns when DoFixedCols = true) to the width of
the text. An additional parameter Padding can be used to add some extra padding width to the
column’s width.
procedure AutoGrowCol(Col: integer);
31
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
98 | Page
Adapts the width of column Col to have all text in cells in this column fit. The width of the column
can only increase when the text is too large, it will never shrink.
procedure AutoGrowColumns(DoFixedCols: Boolean; Padding: integer);
Adapts the width of all columns (including fixed columns when DoFixedCols = true) to the width of
the text. An additional parameter Padding can be used to add some extra padding width to the
column’s width. Equivalent to AutoGrowCol(), the width of the column can only increase when the
text is larger than the column width. The width will never decrease though when calling
AutoGrowColumns().
procedure AutoFitColumns(DoFixedCols: Boolean = true);
Changes the width of all columns proportionally to ensure all columns fill the entire width of the
grid. When DoFixedCols = false, the size of the fixed columns is not affected, only the size of the
normal columns is proportionally changed.
procedure AutoSizeRow(Row: integer);
Adapts the height of row Row to have all text in cells in this row fit.
procedure AutoSizeRows(DoFixedRows: Boolean; Padding: integer);
Adapts the height of all rows (including fixed rows when DoFixedRows = true) to the height of the
text. An additional parameter Padding can be used to add some extra padding width to the row’s
height.
procedure AutoNumberCol(Col: integer);
Fills the rows of a column with a series of numbers, incrementing from first row to total number of
rows. The grid public property AutoNumberOffset sets the value of the first row and the property
AutoNumberStart sets the first row index from where auto numbering should be applied.
procedure AutoNumberRow(Row: integer);
Fills the columns of a row with a series of numbers, incrementing from first column to total number
of columns. The grid public property AutoNumberOffset sets the value of the first column and the
property AutoNumberStart sets the first column index from where auto numbering should be
applied.
29
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
99 | Page
TAdvStringGrid row hover buttons
With TAdvStringGrid it is possible to have a series of buttons automatically hover over the active
row of the grid. This customizable series of buttons can be used for some quick actions such as
clearing the row, inserting preset values etc…
The feature is exposed via grid.HoverButtons that has following properties:
grid.HoverButtons.Buttons: THoverButtonsCollection : collection of buttons
grid.HoverButtons.Column: integer : sets the column where the hover buttons should appear
grid.HoverButtons.Enabled: Boolean : set true to enable this feature
grid.HoverButtons.Position: position where the buttons should be displayed in the selection column
grid.HoverButtons.Rows: selects whether the hover buttons appear for normal rows only or both
normal & fixed rows.
A button on the hover buttons can have:
THoverButton.Caption: string : caption of the button
THoverButton.Enabled: Boolean : enabled state of the button
THoverButton.Flat: Boolean : selects between regular & flat button style
THoverButton.Hint: string : sets the hint for the button
THoverButton.ImageIndex: integer : sets the image from the grid.GridImages imagelist to use on the
button.
THoverButton.Picture: TPicture : sets a picture for use on the hover button
THoverButton.Tag: integer
Below is a sample where 3 hover buttons were added via grid.HoverButtons.Buttons and a PNG
image was set on each button. The grid.HoverButtons.Column was set to column 4, so the
hoverbuttons appear on the row where the mouse hovers on the left side of column 4.
When a hover button is clicked, the event OnHoverButtonClick is triggered, returning the row where
the action happened as well as the button that triggered it.
37
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
100 | Page
TAdvStringGrid nodes
A multi-level hierarchy row expand/contract functionality can be added to TAdvStringGrid through
Nodes. Working with nodes involves three topics:
putting nodes in the grid
node appearance
reacting to node click events
Following functions are available to work with nodes in the grid:
procedure AddNode(aRow,Span:integer);
Adds a node in the grid spanning Span rows
procedure RemoveNode(aRow:integer);
Removes a node at row aRow.
function IsNode(aRow:integer):boolean;
Returns true if the row contains a node
function GetNodeState(ARow:integer):boolean;
Returns true if the node is in contracted state
procedure SetNodeState(ARow:integer;value:boolean);
Sets the state of node
procedure ExpandNode(ARow:integer);
Expands the node at row ARow.
procedure ContractNode(ARow:integer);
Contracts the node at row ARow
procedure ExpandAll;
Expands all nodes
procedure ContractAll;
Contracts all nodes
function GetNodeSpan(aRow: Integer): Integer:
Retrieves the number of rows a node spans
function GetNodeLevel(aRow: Integer): Integer;
Retrieves the depth level of a node
function GetParentRow(aRow: Integer): Integer;
Documents you may be interested
Documents you may be interested