Re: HMG 3.4.0
Posted: Tue Feb 10, 2015 9:36 pm
Thanks Guys, seems I missed this important update.
Serge
Serge
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
https://www.hmgforum.com/
Code: Select all
/*
* HMG Virtual Grid Demo
* (c) 2009 Roberto Lopez
*/
#include "hmg.ch"
Function Main
Local aValue := { 0 , 0 }
local aStructureOfHeaders, aStructureOfPositions
SET EXCLUSIVE ON
//REQUEST("DBFCDX")
// first, we need to create database for test
// we will have 1 to n relation from headers to positions
if file("invoices.dbf")
delete file headers.dbf
endif
if file("positions.dbf")
delete file positions.dbf
endif
aStructureOfInvoices := { { "ID","C",6,0},;
{ "FullNumber","C",11,0} }
aStructureOfPositions := { { "ID","C",6,0},;
{ "Lp","N",2,0 } ,;
{ "TimeStamp","C",20,0},;
{ "AnyText","C",40,0 } }
DBCreate("invoices",aStructureOfInvoices)
DBCreate("positions",aStructureOfPositions)
use invoices new
index on ID to invoices1
set index to invoices1
use positions new
index on ID to positions1
set index to positions1
for i = 20 to 1 STEP -1
invoices->(AddRec())
replace;
invoices->ID with str(i,6,0) ,;
invoices->FullNumber with str(i,6,0)+"/"+str(year(date()),4,0)
for j := 1 to 2+i*2
positions->(AddRec())
replace;
positions->ID with invoices->ID ,;
positions->LP with j ,;
positions->TimeStamp with time() ,;
positions->AnyText with "This is pos.no "+alltrim(str(j,0))+" of header record #"+alltrim(str(i,0))
next j
next i
************************************** I have never used "OrdScope"
*invoices->(DBGoTop())
*positions->(OrdScope(0,invoices->ID))
*positions->(OrdScope(1,invoices->ID))
*positions->(DBGoTop())
**************************************
* Headers Grid Column Controls Definitions
*aInvoicesControls := { {'TEXTBOX','CHARACTER'} ,;
* {'TEXTBOX','CHARACTER'} }
*aPositionsControls := { {'TEXTBOX','CHARACTER'} ,;
* {'TEXTBOX','NUMERIC'} ,;
* {'TEXTBOX','CHARACTER'} ,;
* {'TEXTBOX','CHARACTER'} }
aInvoicesHeaders := { "ID","Number"}
aInvoicesWidths := { 60,120}
*aInvoicesJust := { 0,1}
*aInvoicesFields := {"ID","FullNumber"}
aPositionsHeaders := { "ID","Lp","TimeStamp","Any text" }
aPositionsWidths := { 60,60,100,300 }
*aPositionsJust := { 0,1,0,0 }
*aPositionsFields := { "ID","LP","TimeStamp","AnyText" }
DEFINE WINDOW Form_1 AT 0,0 WIDTH 900 HEIGHT 610 TITLE 'GRID and DBEval() test By AndyGlezL' MAIN
@ 10,10 LABEL L1 VALUE "Invoices"
@ 40,10 GRID Grid_Invoices WIDTH 210 HEIGHT 500 HEADERS aInvoicesHeaders WIDTHS aInvoicesWidths ON CHANGE UpdatePositions( This.Value )
// ROWSOURCE "invoices" ;
// COLUMNFIELDS aInvoicesFields ;
// COLUMNCONTROLS aInvoicesControls ;
// ON CHANGE UpdatePositions( )
// Fill Grid_Invoices
Invoices->( DBEval( { || Form_1.Grid_Invoices.AddItem( { ID, FullNumber } ) } ) )
@ 10,240 LABEL L2 VALUE "Positions"
@ 40,240 GRID Grid_Positions WIDTH 640 HEIGHT 500 HEADERS aPositionsHeaders WIDTHS aPositionsWidths
// ROWSOURCE "positions" ;
// COLUMNFIELDS aPositionsFields ;
// COLUMNCONTROLS aPositionsControls
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return
*******************************************************************************
Procedure AddRec
append blank
return
*******************************************************************************
/*
Procedure UpdatePositions()
// clear previous ordscopes
positions->(OrdScope(0,NIL))
positions->(OrdScope(1,NIL))
positions->(DBGoTop())
MsgInfo("Positions will be set to ID #"+invoices->ID)
positions->(OrdScope(0,invoices->ID))
positions->(OrdScope(1,invoices->ID))
positions->(DBGoTop())
Form_1.Grid_Positions.Refresh
return
*/
Procedure UpdatePositions( nRow ) // New ON CHANGE Procedure UpdatePositions
Form_1.Grid_Positions.DeleteAllItems
cKey := GetProperty( "Form_1", "Grid_Invoices", "CellEx", nRow, 1 ) // Get value from Column 1 of "Grid_Invoices"
positions->( DBSeek( cKey, .T. ) )
positions->( DBEval( { || IF( cKey = ID, Form_1.Grid_Positions.AddItem( { ID, STR( LP ), TimeStamp, AnyText } ), nil ) } ) )
Returncomo que no me quedo claro, estoy utilizando el GRID y el evento ONCHANGE de tu ejemplo con mouse y teclas...but problem, which I want to point doesn't lay in method of viewing positions table.
It lays in firing ONCHANGE code...