TGGrid

From Gestinux Wiki
Jump to navigation Jump to search

It is a descendant of TStringGrid with more functionnalities.

Translation

You must create and give an english title to columns, without space. This title will be used as an identifier to get the translated title from the language inifile. For this it must contain a key with the TGGrid name, a dot, the original column title, a dot, and the keyword Caption

Example :

[TFormXXXX]
Grid1.FirstColumn.Caption=Première colonne
Grid1.SecondColumn.Caption=Deuxième colonne

Column widths

The program can (and should) autosize after the grid is filled, or after change in cell's length .

If the user change the widths of columns, they will be stored in the configuration on exit and restored next time the program runs. In the future, we plan to memorize the order of the columns, allow hiding some of them, and resetting all.

Row insertion and deletion

If the property Readonly is true, the following is of course not relevant.

The property GOptions allows or not adding a row at the bottom, inserting a row, and deleting a row.

  • Appending : one empty row will be always present at the bottom. When it is completed and valid, a new one is created, and so on. An event can be defined to fill default values in cells.
  • Inserting : use the F8 key to insert a row before the current one, or F9 to insert after the current one. An event can be defined to fill default values in cells.
  • Deleting : F10 deletes the current row. An event can be defined to ask for confirmation and/or prevent deletion of the line.

In addition to the Lazarus TStringGrid.OnValidate, there is an OnValidateRow event, which can be called if you need to validate globally the line.

Public methods

Some public methods are available, in addition to those of TStringGrid, to help managing the grid.

  • Translate : can be used when the language is set or changed, for specific needs.
  • NewRowBeforeCurrent : Inserts a new row. called by F9 if allowed in GOptions.
  • NewRowAfterCurrent : Inserts a new row. called by F11 if GOptions allows it.
  • AddRow : append a new row.
  • DeleteRow : Deletes a row. called by F10 if GOptions allows it.
  • DeleteAllRows : empties the grid. Fixed rows are preserved.
  • IsRowValid : this function returns true if all cells in the row are valid, false otherwise. Overrides a True By default.
  • IsRowEmpty : this function returns true if the row entry can be cancelled without loosing data. Overrides a True By default.
  • Initialvalue : this function returns the value displayed in the grid before entry starts.
  • MemoValues : save the values displayed in the grid before entry starts (maybe useless, could be made private).
  • SetColDefaultSize : To be called after the grid is filled or after changes. read the column widths if previously saved, or autosizes the columns otherwise.
  • AddColumn : To add a column. The title is the key in the translation file, and will be translated and preserved for future translations.

See also

Other data entry components