Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Summing Column In QM Grid
#2
QM grid control programming is not easy. Also it is not available in exe. Better use some ActiveX control grid. For example scgrid.

QM_Grid help and definitions in QM.

Function qmgrid
Code:
Copy      Help
;About QM_Grid control

;This control is based on SysListView32 control. You can use its messages, notifications
;and styles. They are documented in the MSDN Library.
;In addition to SysListView32 control functionality, QM_Grid control allows user to edit all
;or some cells, and can also show other controls, such as combo box, check box and button.
;By default, this control can be used to enter text, like with edit control but where each
;line is divided into columns. It also can be used to enter values of multiple properties,
;instead of dialog with multiple controls, similarly as in many programming IDEs.
;By default, to edit cells, is displayed temporary single-line edit control. You can use
;LVM_QG_SETCELLTYPE and/or LVM_QG_SETCOLUMNTYPE to set other control types and styles.
;These control types/styles are supported: single-line edit (default), multiline edit,
;combo box (edit with drop-down list), sorted combo box, check box (sets item text to Yes
;or empty), and none (read-only text). Also, a button can be displayed by the control.

;A. Initializing
;1. Create control of QM_Grid class (for example in dialog editor). Optionally use listview styles.
;2. Optionally set listview extended styles, imagelists.
;3. Optionally send LVM_QG_SETSTYLE.
;4. Add columns (LVM_INSERTCOLUMN).
;5. Optionally send LVM_QG_SETCOLUMNTYPE to set default cell control type for columns (initially it is QG_EDIT).
;6. Add items and subitems. You can use listview messages (LVM_INSERTITEM, etc). Or use LVM_QG_SETALLCELLS to add all cells. Or use ICsv.ToQmGrid. You can add items and subitems in single call, or you can add items only, and later add subitems.
;7. Optionally send LVM_QG_SETCELLTYPE to set control types of separate cells.

;B. Receiving notifications.
;You can optionally process LVN_ and LVN_QG_ notifications.
;You must process LVN_QG_BUTTONCLICK for cells that have QG_BUTTONATRIGHT style. For example, show a dialog and set edit control text.
;You must process LVN_QG_COMBOFILL for cells that have QG_COMBO type. Use CB_ADDSTRING to add combo box items. This message is sent each time before showing dropdown list.
;You optionally can process LVN_QG_COMBOITEMCLICK for cells that have QG_COMBO type. If you don't process it, or process but return 0, combo box edit control text is set to selected item's text. This message allows you to override this behavior. You for example can show a dialog, set edit control text, and return 1.
;Also you can process LVN_ENDLABELEDIT to validate user input, save/apply, etc.

;C. Getting text from cells.
;Use LVM_GETITEMTEXT to get text from each cell you need. Or, use LVM_QG_GETALLCELLS to get all cells. Or use ICsv.FromQmGrid.

;D. Mouse and keyboard navigation.
;Click cell to edit it.
;Click-drag at right or left to select rows. Also, you can Ctrl+Click or Shift+Click.
;Right click or use App key to show context menu.
;In cell edit mode:
,;Use Tab, Shift+Tab or arrows to edit next, prev, below or above.
,;Use Enter to insert and edit new row.
,;Use standard edit control navigation and context menu.
,;Use Esc to deactivate cell edit mode.
;Not in cell edit mode:
,;Use Spacebar to edit first editable cell of selected or first row.
,;Use Ctrl+A to select all, Delete to delete selected, Ctrl+Up/Down to move selected cell.


;//////////////////////////////////////////////////

;Definitions

;Styles (use with LVM_QG_SETSTYLE)
def QG_NOEDITFIRSTCOLUMN 1 ;;does not allow user to edit cells in first column.
def QG_NOAUTOADD 2 ;;does not allow user to add, delete, insert and move rows.
;By default, all cells are editable, and user can easily add, delete and move rows.
;And you can use list view control styles.

;Cell control flags (use with LVM_QG_SETCELLTYPE and LVM_QG_SETCOLUMNTYPE)
;control type
def QG_EDIT 0
def QG_COMBO 1
def QG_CHECK 2
def QG_NONE 7 ;;read-only text
def QG_CONTROLTYPEMASK 7 ;;not used
;control style
def QG_EDIT_MULTILINE 8 ;;use with QG_EDIT
def QG_COMBO_SORT 8 ;;use with QG_COMBO
def QG_BUTTONATRIGHT 16 ;;use with any type
;example: QG_EDIT|QG_EDIT_MULTILINE|QG_BUTTONATRIGHT ;;multiline edit control with button

;LVM_QG_SETALLCELLS flags
def QG_SET_FIRST 1 ;;set only first column
def QG_SET_NOFIRST 2 ;;set all except first column
;LVM_QG_GETALLCELLS flags
def QG_GET_NOFIRST 1 ;;get all except first column
def QG_GET_TRIM 2 ;;trim spaces from cell values

;Messages
def LVM_QG_FIRST (LVM_FIRST+240) ;;not used
def LVM_QG_SETSTYLE (LVM_QG_FIRST) ;;Sets grid style (defined above). wParam is styles, lParam is mask (can be used -1).
def LVM_QG_SETCELLTYPE (LVM_QG_FIRST+1) ;;Sets control flags of a single cell (defined above). wParam is item, lParam is column in low-order word and flags in high-order word (flags<<16|column).
def LVM_QG_SETCOLUMNTYPE (LVM_QG_FIRST+2) ;;Sets default control flags for all cells of specified column (defined above). wParam is column, lParam is flags.
def LVM_QG_SETALLCELLS (LVM_QG_FIRST+3) ;;Populates all cells from a str variable containing multistring. wParam is LVM_QG_SETALLCELLS flags (defined above), lParam is address of the str variable.
def LVM_QG_GETALLCELLS (LVM_QG_FIRST+4) ;;Gets all cells to a str variable as multistring. wParam is LVM_QG_GETALLCELLS flags (defined above), lParam is address of the str variable.

;Notes
;A multistring is array of strings where all strings are in same str variable, each string is terminated with null character. Multistrings can be stored in registry with REG_MULTI_SZ type.
;Checkbox cell text is "Yes" if checked, empty if unchecked.

;Notifications
def LVN_QG_FIRST (LVN_LAST) ;;not used
def LVN_QG_BUTTONCLICK (LVN_QG_FIRST) ;;Sent on button click. Do whatever you want and return 0.
def LVN_QG_COMBOFILL (LVN_QG_FIRST+1) ;;Sent on combobox dropdown. Fill the combo box and return 0.
def LVN_QG_COMBOITEMCLICK (LVN_QG_FIRST+2) ;;Sent on combobox item clicked. Return 0, or 1 to preserve edit control text.
def LVN_QG_CHANGE (LVN_QG_FIRST+3) ;;Sent on cell text changed. Return 0.

;Address of variable of this type is sent with LVN_QG_ notifications as lParam.
;Some members are used only with certain notifications.
type QM_NMLVDATA NMHDR'hdr hctrl hcb ctrltype item subitem cbindex $txt
;hdr - notification code, grid control handle and id.
;hctrl - edit control (not grid control).
;hcb - combo box control.
;ctrltype - cell flags from QM_GRID_ITEM_FLAGS.
;item and subitem - specifies the cell.
;cbindex - on LVN_QG_COMBOITEMCLICK it is index of selected combo box item.
;txt - edit control text.

;Also, the control extends these SysListView32 messages and notifications:
;LVM_EDITLABEL ;;lParam specifies subitem.
;LVN_BEGINLABELEDIT ;;LVITEM.iSubItem specifies subitem.
;LVN_ENDLABELEDIT ;;LVITEM.iSubItem specifies subitem. Return 1 to leave old text.

Example.
Requires QM 2.3.0 or later.

Function dlg_QM_Grid
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

#compile "qmgrid"

if(!ShowDialog("dlg_QM_Grid" &dlg_QM_Grid 0)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 291 175 "QM_Grid"
;3 QM_Grid 0x54200001 0x200 0 0 294 154 ""
;1 Button 0x54030001 0x4 2 158 48 14 "OK"
;2 Button 0x54030000 0x4 52 158 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030003 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,int g=id(3 hDlg)
,;use first column as noneditable
,SendMessage g LVM_QG_SETSTYLE QG_NOEDITFIRSTCOLUMN -1
,;add columns
,LvAddCol g 0 "read-only" 80
,LvAddCol g 1 "edit" 50
,LvAddCol g 2 "edit+button" 80
,LvAddCol g 3 "edit multiline" 80
,LvAddCol g 4 "combo" 80
,LvAddCol g 5 "check" 50
,;set column cell control default types
,SendMessage g LVM_QG_SETCOLUMNTYPE 2 QG_EDIT|QG_BUTTONATRIGHT
,SendMessage g LVM_QG_SETCOLUMNTYPE 3 QG_EDIT|QG_EDIT_MULTILINE
,SendMessage g LVM_QG_SETCOLUMNTYPE 4 QG_COMBO
,SendMessage g LVM_QG_SETCOLUMNTYPE 5 QG_CHECK
,;populate ICsv variable
,ICsv c=CreateCsv; c.Separator=","
,lpstr si=
;a1,b1,c1,d1,e1,yes
;a2,b2,c2,d2,e2,
;,,c3
,c.FromString(si)
,
,;Make sure that ncols is equal to the number of columns in the grid that you want to set (also depends on ToQmGrid flags).
,;If not, ToQmGrid will fail.
,;out "ncols=%i, nrows=%i" c.ColumnCount c.RowCount
,
,;populate grid control
,c.ToQmGrid(g 0)
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,;get and show all cells
,c=CreateCsv; c.Separator=","
,c.FromQmGrid(id(3 hDlg))
,str s
,c.ToString(s)
,mes s
,
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
if(nh.idFrom=3) ret DT_Ret(hDlg gridNotify(nh))

Function gridNotify
Code:
Copy      Help
;/dlg_QM_Grid
function NMHDR*nh

;Examples for all QM_Grid-specific notifications.

NMLVDISPINFO* di=+nh
QM_NMLVDATA* cd=+nh
str s
sel nh.code
,case LVN_BEGINLABELEDIT
,,out "begin edit: item=%i subitem=%i text=%s" di.item.iItem di.item.iSubItem di.item.pszText
,case LVN_ENDLABELEDIT
,,out "end edit: item=%i subitem=%i text=%s" di.item.iItem di.item.iSubItem di.item.pszText
,case LVN_QG_BUTTONCLICK:
,,out "button: item=%i subitem=%i text=%s" cd.item cd.subitem cd.txt
,,if(OpenSaveDialog(0 s))
,,,s.setwintext(cd.hctrl)
,case LVN_QG_COMBOFILL
,,out "combo fill: item=%i subitem=%i" cd.item cd.subitem
,,TO_CBFill cd.hcb "one[]two[]show inp"
,case LVN_QG_COMBOITEMCLICK
,,out "combo click: item=%i subitem=%i cbitem=%i text=%s" cd.item cd.subitem cd.cbindex cd.txt
,,if(cd.cbindex=2)
,,,if(inp(s))
,,,,s.setwintext(cd.hctrl)
,,,,ret 1
,case LVN_QG_CHANGE
,,out "text changed: item=%i, subitem=%i, text=%s, newtext=%s" cd.item cd.subitem cd.txt _s.getwintext(cd.hctrl)

Function LvAddCol
Code:
Copy      Help
;/
function hlv index $txt width

;Adds column to SysListView32 control that has LVS_REPORT style (1).
;To create control with this style, specify 0x54000001 style in dialog definition.
;Index of first colunm is 0.


LVCOLUMNW col.mask=LVCF_WIDTH|LVCF_TEXT
col.pszText=@txt
col.cx=width
SendMessage hlv LVM_INSERTCOLUMNW index &col


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)