CGrid Class Description


The CGrid class provides an alternative to the CGridView class for creating a grid control. Whereas a CGridView creates or attaches a view window, the CGrid class sets up a grid to be opened in a dialog. The dialog may be of either the modeless or modal variety accoding to the standard Windows rules for modeless and modal dialogs:. A modal dialog blocks interaction with windows other than itself. A modeless dialog permits interaction with other windows. A modeless dialog is created using new_griddlgmodal and a modal dialog is created using new_griddlg. After the CGrid is opened into a modeless dialog, further grid processing may be done by attaching its CGridCtrl object using new_gridctrl.

Here is the sequence of operations for creating and using a:

  1. Setup the CGrid using class methods and data.

  2. Open the CGrid into a dialog using new_griddlg or new_griddlgmodal.

  3. Optional: For further work with the modeless dialog's grid control, attach a CGridCtrl using new_gridctrl.

The figure below shows a modeless grid dialog created using new_griddlg, and with various embellishments and script commands added to the pop-up command menu. The modal version of this dialog would be created using new_griddlgmodal. This dialog was by the sample script GridDlg (modeless) test with menu.lua. Note the script commands appearing in the bottom menu group; these were added using the class AddMenu method.

Differences in Grid Creation Methods

Mira provides 3 ways to create or work with a grid control:

  1. Modeless CGrid dialog.

  2. Modal CGrid dialog.

  3. Modeless CGridView view window.

The first two methods are available for the CGrid class discussed in this topic. The CGridView class is described elsewhere. The primary differences between the CGrid and CGridView classes are as follows:

bullet.gif    The CGrid class does not support all features of the CGridView class, including multiple grid sheets.

bullet.gif    The CGridView class may attach an existing grid window from the desktop, whereas the CGrid class cannot attach to an existing grid.

bullet.gif    A modal CGrid dialog stops the script immediately after it is created and takes control of the user interface until the dialog is closed. The script that opened the modal dialog resumes when the dialog closes.

bullet.gif    A modeless CGrid dialog and a CGridView window continues executing the script immediately after opening and become a participating member of the entire Mira desktop.

bullet.gif    A CGridView window and modeless CGrid dialog can execute other scripts while it is open.

bullet.gif    The CGridView and modeless CGrid dialog creation functions both return a CGridView object for working with the displayed grid data. See the discussion below.

 

NOTE:

The Execute Script pop-up menu command is not available for a modal grid dialog. A modal dialog takes control of the user interface as the single top-most window. To execute scripts from a grid window, either create a modeless grid dialog using new_griddlgmodal or use a CGridView window.

The modeless CGrid dialog's Execute Script menu command may be used to open and execute a script directly from a modeless CGrid dialog. A script executed from the CGridView or modeless CGrid is sent a ParentGrid object of type CGridView that provides access to the window's grid data. You can use this name directly in the script or you can rename it, like G = ParentGrid. A sample script to call from a grid window is provided named Execute from Grid Dialog test.lua.

Usage

Construction

Object = CGrid:new()

Object = new_grid()

Destruction

Object:delete()

Creator Functions

These functions are used to create and attach a new CGrid object as an alternative to using the class-based new method. The new_griddlg and new_griddlgmodal methods are the only way to open the CGrid in a new grid dialog.

new_grid

Creates a new instance of the CGrid class. This is an alternative to the CGrid:new method.

new_griddlg

Opens the CGrid object in a modeless dialog.

new_griddlgmodal

Opens the CGrid object in a modal dialog

Construction and Destruction - Class Methods

new

Creates a new instance of a CGridView object. The grid defaults may also be set using the GridParams table.

delete

Deletes the instance of the CGrid object.

GridParams table

The GridParams table may be used to initialize the properties of the new CGrid object when created.

CGrid Methods

AddMenu

Adds a script command to the pop-up menu of the modeless grid dialog.

AddMenuExecute

Adds an "Execute Script" command to the pop-up menu of the modeless grid dialog.

BestFit

Adjusts the grid within the window for best fit over a range of columns.

DeleteMenus

Deletes all script commands from the grid dialog's menu.

TH_FindCol

Finds the top heading column containing the specified string. This is often used to find a grid column using its top heading title.

SH_FindRow

Finds the side heading row containing the specified string. This is often used to find a grid row using its side heading title.

FindCell

Finds the grid cell column and row containing the specified string.

GetNumCols

Returns the number of columns in the grid.

GetNumRows

Returns the number of rows in the grid.

Get

Returns the value of a grid cell.

GotoCell

Sends the grid cursor to the specified cell.

JoinCells

Joins a block of cells into a single cell.

Optimize

Optimizes the width of all columns.

OptimizeRange

Optimizes the widths over a column range.

SetBkColor

Sets the background color of a cell.

SetFontColor

Sets the fot color color of a cell.

SetHorzAlign

Sets the text alignment for a grid column.

SetColWidth

Sets the width of a grid column.

SetVertAlign

Sets the vertical text alignment for a grid row.

SetRowStretch

Sets the vertical stretch factor for a grid row.

SetSH_HorzAlign

Sets the horizontal text alignment of a side heading column.

SetSH_Title

Sets the title of a side header cell.

SetSH_Titles

Sets all titles for a side header column.

SetTH_RowStretch

Sets the vertical stretch factor for a grid heading rows.

SetTH_Title

Sets the title of a top header cell.

SetTH_Titles

Sets all titles for a top header row.

SetTH_VertAlign

Sets the vertical text alignmentfor top heading rows.

SetSH_Width

Sets the width of the side header in screen pixels.

SetFontColor

Sets the text color of a cell.

Set

Sets the grid cell value.

SetHorzAlign

Set the horizontal alignment of specific cells or an entire column. The default alignment is "left".

SetVertAlign

Set the vertical alignment of specific cells or an entire row. The default alignment is "center".

Related Topics

Script Classes

CGridCtrl class

CGridView class

new_griddlg

new_griddlgmodal

Contents


Mira Pro x64 Script User's Guide, v.8.77 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.