Grid control (QM_Grid)

Changes in QM 2.3.2

Before QM 2.3.2, this control was almost undocumented. Some samples were in the forum. In QM 2.3.2 it is documented, easier to use, and has many enhancements:

Where to use

The control can be used in dialogs and other windows to:

How to use

How to add to a dialog

Use Dialog Editor. It also allows you to define style and columns.

 

You also can define style and columns at run time. Use class DlgGrid. See function sample_Grid.

 

How to set data

Dialog Editor generates code that includes variables for grid controls. Before calling ShowDialog, assign a string in CSV format to a grid variable. To load and process CSV, use ICsv interface.

 

You can also set data using class DlgGrid. See function sample_Grid.

 

How to get data

When ShowDialog returns on OK, the variable contains string in CSV format. To process and save it, use ICsv interface.

 

You can also get data using class DlgGrid. See function sample_Grid.

 

How to work with the control in dialog procedure

Use class DlgGrid. See function sample_Grid.

 

Also you can use grid control and list view control (SysListView32) messages, notifications, types and constants.

 

Grid control messages etc are documented below, in grid.h. In QM they are declared in reference file GRID. Use like this: GRID.LVN_QG_COMBOFILL.

 

List view control messages etc are documented in MSDN Library. They are declared in reference files WINAPI and WINAPIV.

 

How to set control types for rows or cells

In dialog procedure use functions of class DlgGrid.

 

If the grid has style "Can be set row control type" (QG_SETROWTYPE), you also can set row control types when adding text. Use syntax: <type>text in first column cells. Read more below, in Details.

 

Example

\Dialog_Editor

str controls = "3"
str qmg3
qmg3=
 <0>edit,x
 <1>combo,x
 <2>check,Yes
 <7>read-only,x
 <8>edit multiline,x
 <9>combo sorted,x
 <16>edit+button,x
 <17>combo+button,x
 
if(!ShowDialog("Dialog90" 0 &controls)) ret
out qmg3

 BEGIN DIALOG
 0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
 3 QM_Grid 0x54030000 0x0 0 0 224 110 "7,0,0,2[]A,,[]B,,[]"
 1 Button 0x54030001 0x4 120 116 48 14 "OK"
 2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
 END DIALOG
 DIALOG EDITOR: "" 0x2030202 "*" "" ""

 

How to set icons, lparam and other list view control item properties

In dialog procedure use functions of class DlgGrid.

 

To add icons, at first create imagelist with QM imagelist editor. It is in code toolbar. It also can create code to load the imagelist. In dialog procedure, load the imagelist (__ImageList.Load), attach it to the control (DlgGrid.SetImagelist), and assign icon indices (DlgGrid.RowPropSet or DlgGrid.RowAddSetX).

 

If the grid has style "Can be set row control type" (QG_SETROWTYPE), you also can set these properties when adding text. Read more below, in Details. See function sample_Grid_images.

 

How to use with databases

It is easy with sqlite databases. Use Sqlite class. It can display table in grid control. See function sample_Grid_Sqlite.

 

To use with other database types, use Database and DlgGrid classes. Currently there are no functions that would transfer whole table from/to database to grid control. You will have to do it for each row.

 

How to use in exe

QM grid control lives in a QM dll qmgrid.dll. It is not available on computers where QM is not installed.

 

You can add the dll to exe. Add this line somewhere near the beginning of exe code:

 

ExeQmGridDll

 

When creating exe, it adds qmgrid.dll to exe resources. At run time it extracts to the temporary folder and loads.

 

If you don't want to add the dll to exe: take qmgrid.dll from QM folder; add to a zip file or setup program together with exe; on other computers extract them to the same folder. If you use grid controls in a dialog or with CreateControl, exe loads the dll when need. Else load the dll with LoadLibrary.

Details

The class name is QM_Grid. Implemented in qmgrid.dll.

 

Grid row properties

If grid control has "Can be set row control type" style (GRID.QG_SETROWTYPE, 4):

 

1. When you set control type of the first cell in a row, it also sets control type for other cells in the row.

 

2. When adding a row, you can specify row control type and/or other row properties in first cell's text.

Syntax:

 <ctype/lparam/image/overlayImage/stateImage/indent/ctypes>text

 

ctype - row control type. See below.

lparam - a user-defined int value. Or can be any string.

image - image index. Use -1 for no image.

overlayImage - overlay image index.

Valid values are 1 to 15. Index 0 will not add overlay image.

Overlay images are drawn transparently over normal images.

To define overlay images, use __ImageList.SetOverlayImages or ImageList_SetOverlayImage with the main imagelist.

stateImage - state image index.

Valid values are 1 to 15. Index 0 will not add state image.

The index is 1-based, therefore index 1 will display image 0 from the state imagelist.

State images are drawn in the space reserved to the left from normal images.

Must be set state imagelist or checkboxes style.

If checkboxes style, use stateImage 1 and 2 for unchecked and checked.

indent - indent. It is number of image widths. Valid values are -1 to 254.

ctypes - list of cell control types. Use . to inherit from ctype or column. Use -1 to inherit from column. Example: .0 -1..2

 

All parts are optional. For example, can be <ctype>text, or <//image>text.

All numbers must be simple numbers, not constant names or expressions.

To display images and indent, imagelist must be set. Use DlgGrid.SetImagelist.

Row properties also can be set/retrieved using DlgGrid functions.

If style "User cannot edit first column" (GRID.QG_NOEDITFIRSTCOLUMN, 1) also is set, will not remove the <...> string. Just will not display it.

 

Control types

0 edit.
1 combo.
2 check.
3 date.
7 read-only.
8 (0|8) edit multiline.
9 (1|8) combo sorted.
11 (3|8) time.
16 (flag) with button.
23 (7|16) read-only edit + button.

 

C++ header file

grid.h