GRID CHANGE COL

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

GRID CHANGE COL

Post by tomtagaris »

I WANT TO LEARN HOW TO CHANGE FROM ONE COL TO THREE COL IN GRID WHEN I PUSH ENTER BUTON
PLEASE HELP
THANKS
TOM TAGARIS
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: GRID CHANGE COL

Post by edk »

Hi Tom.
I'm not sure if I understood your request correctly (my English is not very good) but I made an example: after editing the field in the first column, the next column is skipped and jumped to the third column.

Code: Select all

#include "hmg.ch"

Function Main

Local aRows [20] [3]


	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		
		@ 50,10 GRID Grid_Master ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
			JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION ;
			ON INPLACEEDITEVENT ProcGridInplaceEditEvent()


		@ 240,10 GRID Grid_Detail ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 ;
			EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
			JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER };
			ON INPLACEEDITEVENT ProcGridInplaceEditEvent()
                	
                	
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return


***********************************
FUNCTION ProcGridInplaceEditEvent()
Local  lCellNavigation := _HMG_SYSDATA [ 32 ] [_HMG_SYSDATA [ 203 ]]
Static lInitByDblClick := .F.

   DO CASE

      CASE This.IsInplaceEditEventInit == .T.
		lInitByDblClick := _HMG_GridEx_InplaceEdit_nMsg == WM_LBUTTONDBLCLK
      
      CASE This.IsInplaceEditEventRun == .T.

      CASE This.IsInplaceEditEventFinish == .T.
      
		IF lCellNavigation
			IF _HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] = 1										//first column
				_HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] := _HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] + IF (lInitByDblClick, 2, 1)	//skip one column
			ENDIF
		ELSE
			IF _HMG_SYSDATA [ 340 ] = 1						//first column
				_HMG_SYSDATA [ 340 ] := _HMG_SYSDATA [ 340 ] + IF (lInitByDblClick, 2, 1)	//skip one column
			ENDIF
		ENDIF
   ENDCASE

RETURN NIL
**********************************
Edk.
User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

Re: GRID CHANGE COL

Post by tomtagaris »

thank you so much adk for the reply the program works but because the grid have five col and in the COLUMNWHEN { { || .t. },{ || .T. }, { || .t. }, { || .t. }, { || .f. }} five col is .f. have this error see in pfoto
thanks
Attachments
2019-07-25.png
2019-07-25.png (290.2 KiB) Viewed 3779 times
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: GRID CHANGE COL

Post by edk »

I'm sorry, but without providing more details, especially the source code, I can not help.
Besides, my code is a "dirty", and it certainly will not work in any case.

Despite this, my example, extended with the COLUMNWHEN clause, works correctly:

Code: Select all

#include "hmg.ch"

Function Main

Local aRows [20] [3]


	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555','non editable','1'}
		aRows [2]	:= {'Mulder','Fox','324-6432','non editable','2'} 
		aRows [3]	:= {'Smart','Max','432-5892','non editable','3'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332','non editable','4'} 
		aRows [5]	:= {'Kirk','James','346-9873','non editable','5'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654','non editable','6'} 
		aRows [7]	:= {'Flanders','Ned','435-3211','non editable','7'} 
		aRows [8]	:= {'Smith','John','123-1234','non editable','8'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000','non editable','9'} 
		aRows [10]	:= {'Gomez','Juan','583-4832','non editable','10'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332','non editable','11'} 
		aRows [12]	:= {'Borges','Javier','326-9430','non editable','12'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898','non editable','13'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473','non editable','14'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843','non editable','15'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983','non editable','16'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984','non editable','17'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873','non editable','18'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????','non editable','19'} 
		aRows [20]	:= {'Reyes','Monica','432-5836','non editable','20'} 

		
		@ 50,10 GRID Grid_Master ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone','Col 4','Col 5'} ;
			WIDTHS {140,140,140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
			COLUMNWHEN { { || .t. },{ || .T. }, { || .t. }, { || .F. }, { || .T. }} ;
	        	JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT , GRID_JTFY_RIGHT , GRID_JTFY_RIGHT } ;
			CELLNAVIGATION ;
			ON INPLACEEDITEVENT ProcGridInplaceEditEvent()


		@ 240,10 GRID Grid_Detail ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone','Col 4','Col 5'} ;
			WIDTHS {140,140,140,140,140};
			ITEMS aRows ;
			VALUE 1 ;
			EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			COLUMNWHEN { { || .t. },{ || .T. }, { || .t. }, { || .F. }, { || .T. }} ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
	               JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER, GRID_JTFY_CENTER, GRID_JTFY_CENTER };
        	       ON INPLACEEDITEVENT ProcGridInplaceEditEvent()
                	
                	
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return


***********************************
FUNCTION ProcGridInplaceEditEvent()
Local  lCellNavigation := _HMG_SYSDATA [ 32 ] [_HMG_SYSDATA [ 203 ]]
Static lInitByDblClick := .F.

   DO CASE

      CASE This.IsInplaceEditEventInit == .T.
      	lInitByDblClick := _HMG_GridEx_InplaceEdit_nMsg == WM_LBUTTONDBLCLK
      
      CASE This.IsInplaceEditEventRun == .T.

      CASE This.IsInplaceEditEventFinish == .T.
      
      	IF lCellNavigation
      		IF _HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] = 1											//first column
      			_HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] := _HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] + IF (lInitByDblClick, 2, 1)	//skip one column
      		ENDIF
      	ELSE
      		IF _HMG_SYSDATA [ 340 ] = 1				//first column
      			_HMG_SYSDATA [ 340 ] := _HMG_SYSDATA [ 340 ] + IF (lInitByDblClick, 2, 1)		//skip one column
      		ENDIF
      	ENDIF
   ENDCASE

RETURN NIL
**********************************
User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

Re: GRID CHANGE COL

Post by tomtagaris »

@ 250,20 GRID invoice ;
WIDTH 900 ;
HEIGHT 200;
HEADERS { 'Κωδικός','Είδος', 'Ποσότητα', 'Τιμή','Έκπτωση %','Σύνολο', 'Ποσό Φπα', 'ΦΠΑ','Μ.Μ'} ;
WIDTHS {75, 200,100, 100,100, 100, 100,50,50 };
COLUMNCONTROLS { { 'TEXTBOX' }, { 'TEXTBOX' },;
{ 'TEXTBOX', 'NUMERIC', '999999.999' }, ;
{ 'TEXTBOX', 'NUMERIC', '9999.99' }, ;
{ 'TEXTBOX', 'NUMERIC', '999,99' }, ;
{ 'TEXTBOX', 'NUMERIC', '999999.999' }, ;
{ 'TEXTBOX', 'NUMERIC', '999,999.99' }, ;
{ 'TEXTBOX', 'NUMERIC', '99' },{ 'TEXTBOX' }} ;
COLUMNWHEN { { || .t. },{ || .T. }, { || .t. }, { || .t. }, { || .f. }, { || .f. }, { || .F. },{ || .F. },{ || .F. }};
justify { 0,0, 1, 1, 1,1,1 ,1,1} ;
VALUE 1 ;
Edit ;
ON GOTFOCUS CalcFPA() ;
ON key (OnKeyx(),endfil());
ON INPLACEEDITEVENT OnKeyx()
*********************************************************************************
function endfil()
local x:= KATAXORISI.invoice.Itemcount
local i:=KATAXORISI.invoice.value
IF HMG_GetLastVirtualKeyDown () == VK_DOWN //.and. i > x

if x>33 .and. i=x
msgbox('Το όριο εγγραφών στο τιμολόγιο είναι 33','Προσοχή!!!!!!!')
RETURN
ELSE
if KATAXORISI.invoice.value=x // aν ο δεικτης ειναι στην τελευταια εγγραφη τοτε προσθεσε και αλλη εγγραφη
KATAXORISI.invoice.additem( {"","",0,0,0,0,0,0,''} )

for i = 1 to KATAXORISI.invoice.Itemcount
KATAXORISI.invoice.value:=i
KATAXORISI.invoice.setfocus
// setproperty("KATAXORISI","invoice","CellEx ",i,4)
next
endif
ENDIF

endif
RETURN NIL
********************************************************************************
Function OnKeyx()
Local lCellNavigation := _HMG_SYSDATA [ 32 ] [_HMG_SYSDATA [ 203 ]]
local i,nIctr
Local aValue := { }
Static lInitByDblClick := .F.
// IF HMG_GetLastVirtualKeyDown() == 13 //F2

if This.IsInplaceEditEventInit == .T.
lInitByDblClick := _HMG_GridEx_InplaceEdit_nMsg == WM_LBUTTONDBLCLK
endif

DO CASE
CASE This.IsInplaceEditEventFinish == .T.
IF lCellNavigation
IF _HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] = 1 //first column
_HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] := _HMG_SYSDATA [ 15 ] [_HMG_SYSDATA [ 203 ]] + IF (lInitByDblClick, 2, 1) //skip one column
ENDIF
ELSE
IF _HMG_SYSDATA [ 340 ] = 1 //first column
_HMG_SYSDATA [ 340 ] := _HMG_SYSDATA [ 340 ] + IF (lInitByDblClick, 2, 1) //skip one column
ENDIF
Endif
ENDCASE

IF This.IsInplaceEditEventFinish == .T.

i := KATAXORISI.invoice.value
aValue:= KATAXORISI.invoice.value //item( i )
nIctr := KATAXORISI.invoice.cell( i, 2)

if This.CellColIndex = 1 .and. ! empty(KATAXORISI.invoice.cell( i, 1))
Select 1
index on code to apoteke_code
seek KATAXORISI.invoice.cell( i, 1)
if found()
KATAXORISI.invoice.cell( i,1):=CODE
KATAXORISI.invoice.cell( i,2):=EIDOS
KATAXORISI.invoice.cell( i,3):=0
KATAXORISI.invoice.cell( i,4):=PRICE
KATAXORISI.invoice.cell( i,5):=ekptosi
KATAXORISI.invoice.cell( i,6):=0
KATAXORISI.invoice.cell( i,7):=0
KATAXORISI.invoice.cell( i,8):=FPA
KATAXORISI.invoice.cell( i,9):= APOTEKE->MM

else
msginfo('O Kωδικός δέν Υπαρχει..','Προσοχή')
endif
endif


if This.CellColIndex=2 .and. empty(KATAXORISI.invoice.cell( i, 1))
SERCH2( KATAXORISI.invoice.cell( i, 2))

endif

endif


Return
User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

Re: GRID CHANGE COL

Post by tomtagaris »

this is the code
thanks
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: GRID CHANGE COL

Post by edk »

Hi.
From the given piece of code, I still do not have a full picture of the situation when the problem occurs.
My guess is that line 431 is Local lCellNavigation: = _HMG_SYSDATA [32] [_HMG_SYSDATA [203]]

You have mixed up various events and handle them with the same procedure, which can cause errors:
ON key (OnKeyx (), endfil ());
ON INPLACEEDITEVENT OnKeyx ()

Note that This.IsInplaceEdit* properties are only available for the OnInplaceEditEvent event, and you also refer to them in the OK KEY event. This also applies to the variable _HMG_SYSDATA [203]

Personally, I would make separate functions for these events.

You can still try to replace the variable reference _HMG_SYSDATA [203] to GetControlIndex (This.InplaceEditGridName, This.InplaceEditParentName) but the This.InplaceEdit* property is also only available for the OnInplaceEditEvent event.

The changed procedure looks like this:

Code: Select all

FUNCTION ProcGridInplaceEditEvent()
Local index := GetControlIndex ( This.InplaceEditGridName , This.InplaceEditParentName )
Static lInitByDblClick := .F.

   DO CASE

      CASE This.IsInplaceEditEventInit == .T.
      	lInitByDblClick := _HMG_GridEx_InplaceEdit_nMsg == WM_LBUTTONDBLCLK
      
      CASE This.IsInplaceEditEventRun == .T.

      CASE This.IsInplaceEditEventFinish == .T. .AND. index > 0
      	
      	IF _HMG_SYSDATA [ 32 ] [index]		//is Cell Navigation?
      		IF _HMG_SYSDATA [ 15 ] [index] = 1											//first column
      			_HMG_SYSDATA [ 15 ] [index] := _HMG_SYSDATA [ 15 ] [index] + IF (lInitByDblClick, 2, 1)	//skip one column
      		ENDIF
      	ELSE
      		IF _HMG_SYSDATA [ 340 ] = 1				//first column
      			_HMG_SYSDATA [ 340 ] := _HMG_SYSDATA [ 340 ] + IF (lInitByDblClick, 2, 1)		//skip one column
      		ENDIF
      	ENDIF
   ENDCASE

RETURN NIL
In addition, you can simplify the function if your Grid does not have Cell Navigation:

Code: Select all

FUNCTION ProcGridInplaceEditEvent()
Static lInitByDblClick := .F.

   DO CASE

      CASE This.IsInplaceEditEventInit == .T.
      	lInitByDblClick := _HMG_GridEx_InplaceEdit_nMsg == WM_LBUTTONDBLCLK
      
      CASE This.IsInplaceEditEventRun == .T.

      CASE This.IsInplaceEditEventFinish == .T. 
      		IF _HMG_SYSDATA [ 340 ] = 1				//first column
      			_HMG_SYSDATA [ 340 ] := _HMG_SYSDATA [ 340 ] + IF (lInitByDblClick, 2, 1)		//skip one column
      		ENDIF
      	ENDIF
   ENDCASE

RETURN NIL
User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

Re: GRID CHANGE COL

Post by tomtagaris »

THANK YOU adk FOR THE BEAUTIFUL WORLD WORKING NOW VERY WELL
BECAUSE COME FROM CLIPPER I DO NOT UNDERSTAND WHAT THIS IS _HMG_SYSDATA [ ΧΧ] PLEASE CAN YOU explain
SORY FROM MY ENGLISH
THANKS
TOMTAGARIS
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: GRID CHANGE COL

Post by edk »

_HMG_SYSDATA is a multidimensional matrix in which all the parameters necessary for the functioning of HMG are stored.
See the contents of the file h_init.prg, there are basic references - the file is placed in the HMG installation folder in the SOURCE subfolder.

Understanding individual _HMG_SYSDATA arrays requires reanalyzing HMG sources. Therefore, source codes containing direct references to _HMG_SYSDATA and their manipulation affect the entire HMG and may lead to its unstable work.

The _HMG_SYSDATA [340] variable stores the number of the currently edited cell.
Normally, after editing the cell, HMG increases the value of _HMG_SYSDATA [340] by one (ie it will go to the next column - unless it is the last one, then it gets the value 1) and restart the editing process the cell number _HMG_SYSDATA [340].
In the case of _HMG_SYSDATA [340] ++, we cheat HMG.

In order to skip the edition of column No. 2 we implement the following scenario: when we finish editing the cell, where _HMG_SYSDATA [340] = 1, change the value _HMG_SYSDATA [340] to 2, then after the event, HMG will increase the value by one again, then _HMG_SYSDATA [340] will have a value of 3, and HMG will start editing cell number 3.
Last edited by edk on Fri Jul 26, 2019 11:23 am, edited 1 time in total.
User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

Re: GRID CHANGE COL

Post by tomtagaris »

Thank you very much
your help was valuable
tomtagaris
Post Reply