Programming C++Builder What is the Grids and How to Use Grids in CBuilder or Delphi

What's the Grids?

Grids is the component which can display information in rows and columns. If you're writing a database application, use the TDBGrid or TDBCtrlGrid component described in "Using data controls." Otherwise, use a standard draw grid or string grid.

What is the Draw Grid?

A draw grid (TDrawGrid) displays arbitrary data in tabular format. Write an OnDrawCell event handler to fill in the cells of the grid.

  1. The CellRect method returns the screen coordinates of a specified cell, while the MouseToCell method returns the column and row of the cell at specified screen coordinates. The Selection property indicates the boundaries of the currently selected cells.
  2. The TopRow property determines which row is currently at the top of the grid. The LeftCol property determines the first visible column on the left. VisibleColCount and VisibleRowCount are the number of columns and rows visible in the grid.
  3. You can change the width or height of a column or row with the ColWidths and RowHeights properties. Set the width of the grid lines with the GridLineWidth property. Add scroll bars to the grid with the ScrollBars property.
  4. You can choose to have fixed or non-scrolling columns and rows with the FixedCols and FixedRows properties. Assign a color to the fixed columns and rows with the FixedColor property.
  5. The Options, DefaultColWidth, and DefaultRowHeight properties also affect the appearance and behavior of the grid.

To Use the basic gird--String Grid

The string grid component is a descendant of TDrawGrid that adds specialized functionality to simplify the display of strings. The Cells property lists the strings for each cell in the grid; the Objects property lists objects associated with each string. All the strings and associated objects for a particular column or row can be accessed through the Cols or Rows property.

How to edit the values of grid?--Using the value list editors (VCL only)

TValueListEditor is a specialized grid for editing string lists that contain name/value pairs in the form Name=Value. The names and values are stored as a TStrings descendant that is the value of the Strings property. You can look up the value for any name using the Values property. TValueListEditor is not available for cross-platform programming.

The grid contains two columns, one for the names and one for the values. By default, the Name column is named "Key" and the Value column is named "Value". You can change these defaults by setting the TitleCaptions property. You can omit these titles using the DisplayOptions property (which also controls resize when you resize the control.)

You can control whether users can edit the Name column using the KeyOptions property. KeyOptions contains separate options to allow editing, adding new names, deleting names, and controlling whether new names must be unique.

You can control how users edit the entries in the Value column using the ItemProps property. Each item has a separate TItemProp object that lets you

  1. Supply an edit mask to limit the valid input.
  2. Specify a maximum length for values.
  3. Mark the value as read-only.
  4. Specify that the value list editor displays a drop-down arrow that opens a pick list of values from which the user can choose or an ellipsis button that triggers an event you can use for displaying a dialog in which users enter values.

If you specify that there is a drop-down arrow, you must supply the list of values from which the user chooses. These can be a static list (the PickList property of the TItemProp object) or they can be dynamically added at runtime using the value list editor's OnGetPickList event. You can also combine these approaches and have a static list that the OnGetPickList event handler modifies.

If you specify that there is an ellipsis button, you must supply the response that occurs when the user clicks that button (including the setting of a value, if appropriate). You provide this response by writing an OnEditButtonClick event handler.

Add comment

Security code

Programming - C++Builder