Page 1 of 1

Messages in a GRID

Posted: Sun May 29, 2016 6:15 pm
by TopsMarc
Hi,

In GRID_15 sample, when I enter a wrong value in column 1, the default grid message 'Invalid Entry' appears.
When I enter a wrong value in column 2, the same default message appears.
I modified the sample so I get a different message, for column 1 'Value must be > 100' and column 2 'Date must be today'.
I do this by changing HMG_SYSDATA [ 136 ][11]. Is there a more elegant way ?

Kind regards, Marc

Re: Messages in a GRID

Posted: Sun May 29, 2016 11:25 pm
by ASESORMIX
Observa este ejemplo, te podria ayudar

Code: Select all

      /*
* HMG Grid Demo
* (c) 2005 Roberto Lopez
*/

#include "hmg.ch"

Function Main

Local aRows [20] [3]

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 640 ;
      HEIGHT 400 ;
      TITLE 'Mixed Data Type Grid Test' ;
      MAIN 

      DEFINE MAIN MENU
         DEFINE POPUP 'File'
            MENUITEM 'Exit'   ACTION ThisWindow.Release
         END POPUP
      END MENU

      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'} 

      @ 10,10 GRID Grid_1 ;
         WIDTH 620 ;
         HEIGHT 330 ;
         HEADERS {'Column 1','Column 2','Column 3'} ;
         WIDTHS {140,140,140} ;
         ITEMS aRows ;
         EDIT ;
         COLUMNVALID    { ;
               { || Test1() } , ;
               { || Test2( This.CellValue ) } , ;
               { || Test3( This.CellValue ) } ;
               } 

   END WINDOW

   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return


Procedure Test1()

   If Empty (This.CellValue)

      This.CellValue := '*'

   EndIf

Return


Procedure Test2(cValor)
cValor := ALLTRIM(cValor)
   If cValor == ""
     *MsgBox("Di lo que quieras que aparesca")
      This.CellValue := ''
      RETURN(.F.)
   EndIf
Return(.T.)

Procedure Test3(cValor)
cValor := ALLTRIM(cValor)
   If cValor == ""
      MsgBox("Di lo que quieras que aparesca")
      This.CellValue := 'COMO ESTAS HOY'
   EndIf
Return

Re: Messages in a GRID

Posted: Mon May 30, 2016 7:55 pm
by TopsMarc
Hi Asesormix,

Thank you for the example. I'm sorry I can't write to you in Spanish.

When I enter a wrong value, I want to show a msgbox with a decent message e.g. value must be > 100 (not the default 'invalid entry'), and then the cursor must stay in the input field.
In your example, in column 3 a descent message is given indeed, but the cursor leaves the input field and returns to the grid. But I don't want it to leave the input field.
The BROWSE has a property VALIDMESSAGES. But the GRID doesn't have this I think. How then can that be done in the GRID ?

Gracias. Kind regards, Marc

Re: Messages in a GRID

Posted: Mon May 30, 2016 8:43 pm
by ASESORMIX
Hello, your example corrected ...

Code: Select all

/*
* HMG Grid Demo
* (c) 2005 Roberto Lopez
*/

#include "hmg.ch"

Function Main

Local aRows [20] [3]

SET DATE FORMAT 'dd/mm/yyyy' 

	Private fColor := { || if ( This.CellRowIndex/2 == int(This.CellRowIndex/2) , { 0,0,255 } , { 0,255,0 } ) }	

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 ;
		HEIGHT 400 ;
		TITLE 'Mixed Data Type Grid Test' ;
		MAIN 

		DEFINE MAIN MENU
			DEFINE POPUP 'File'
				MENUITEM 'Set Item'	ACTION SetItem()
				MENUITEM 'Get Item'	ACTION GetItem()
			END POPUP
		END MENU

		aRows [1]	:= {113.12,date(),1,1 , .t. }
		aRows [2]	:= {123.12,date(),2,2 , .f. } 
		aRows [3]	:= {133.12,date(),3,3, .t. } 
		aRows [4]	:= {143.12,date(),1,4, .f. } 
		aRows [5]	:= {153.12,date(),2,5, .t. } 
		aRows [6]	:= {163.12,date(),3,6, .f. } 
		aRows [7]	:= {173.12,date(),1,7, .t. } 
		aRows [8]	:= {183.12,date(),2,8, .f. } 
		aRows [9]	:= {193.12,date(),3,9, .t. } 
		aRows [10]	:= {113.12,date(),1,10, .f. } 
		aRows [11]	:= {123.12,date(),2,11, .t. } 
		aRows [12]	:= {133.12,date(),3,12, .f. } 
		aRows [13]	:= {143.12,date(),1,13, .t. } 
		aRows [14]	:= {153.12,date(),2,14, .f. } 
		aRows [15]	:= {163.12,date(),3,15, .t. } 
		aRows [16]	:= {173.12,date(),1,16, .f. } 
		aRows [17]	:= {183.12,date(),2,17, .t. } 
		aRows [18]	:= {193.12,date(),3,18, .f. } 
		aRows [19]	:= {113.12,date(),1,19, .t. } 
		aRows [20]	:= {123.12,date(),2,20, .f. } 

		@ 10,10 GRID Grid_1 ;
			WIDTH 620 ;
			HEIGHT 330 ;
			HEADERS {'Column 1','Column 2','Column 3','Column 4','Column 5'} ;
			WIDTHS {140,140,140,140,140} ;
			ITEMS aRows ;
			EDIT ;
			COLUMNCONTROLS { ;
					{'TEXTBOX','NUMERIC','$ 999,999.99'} , ;
					{'DATEPICKER','DROPDOWN'} , ;
					{'COMBOBOX',{'One','Two','Three'}} , ;
					{ 'SPINNER' , 1 , 20 } , ;
					{ 'CHECKBOX' , 'Yes' , 'No' } ;
					} ;
			COLUMNVALID	{ ;
					{ || ErrorColumn1() } , ;
					{ || ErrorColumn2() } , ;
					Nil , ;
					Nil , ;
					Nil ;
					}


	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

FUNCTION ErrorColumn1()
	LOCAL lReturn
	IF This.CellValue > 100 
		lReturn := .T.
	ELSE
		lReturn := .F. 
	*_HMG_SYSDATA [ 136 ][11] := 'Value must be > 100'
    MsgBox('Value must be > 100')
    
	ENDIF
RETURN lReturn

FUNCTION ErrorColumn2()
	LOCAL lReturn
	IF This.CellValue = Date()
		lReturn := .T.
	ELSE
		lReturn := .F. 
	*_HMG_SYSDATA [ 136 ][11] := 'Date must be today'
    MsgBox('Date must be today')
	ENDIF
RETURN lReturn

PROCEDURE SETITEM()

	Form_1.Grid_1.Item (2) := { 123.45 , date() , 2 , 10 , .T. }

RETURN

PROCEDURE GETITEM()
local a

	a := Form_1.Grid_1.Item (2) 

	msginfo ( str ( a [1] )				, '1' )
	msginfo ( dtoc ( a [2] )			, '2' )
	msginfo ( str( a [3] )				, '3' )
	msginfo ( str ( a [4] )				, '4' )
	msginfo ( if ( a [5] == .t. , '.t.' , '.f.' )	, '5' )

RETURN





Re: Messages in a GRID

Posted: Mon May 30, 2016 9:05 pm
by TopsMarc
Hi Asesormix,

When I run your corrected example, I do get the decent error message I want, but it is followed by the default message 'Invalid Entry' (see print screen).
I don't want 2 messages, but only my own error message. Can that be done in the grid ?

Kind regards, Marc

Re: Messages in a GRID

Posted: Tue May 31, 2016 6:01 am
by bpd2000
Temporary solution:
Second message comes from line no. 1511 of h_grid.prg, disable message [i.e. // MSGEXCLAMATION ( _HMG_SYSDATA [ 136 ][11] )]
rebuild lib and continue with your example

Re: Messages in a GRID

Posted: Tue May 31, 2016 6:45 pm
by TopsMarc
Hi bpd2000,

Thank you for your solution. That works :-)

I think there is only one small disadvantage. When Claudio/Rathi launch a new HMG release, this modification will be lost, so I would have do it again with every release. But that's easy. Or maybe one day the GRID will have a property ValidMessages like the BROWSE ?

Best regards, Marc

Re: Messages in a GRID

Posted: Wed Jun 01, 2016 12:40 am
by srvet_claudio
I will include

Re: Messages in a GRID

Posted: Wed Jun 01, 2016 6:31 pm
by TopsMarc
srvet_claudio wrote:I will include
That would be very nice. Thank you Claudio.
Best regards, Marc

Messages in a GRID

Posted: Fri Mar 24, 2017 12:01 pm
by Pablo César
Default Messages... :roll:

Misc, Browse, Edit and Extended Edit messages and in different languages...

It is something that would be very good to unlink from the HMG code.
Safe, critical error messages should all be the responsibility of the user. This measure of unlinking from the code would release several elements of the _HMG_SYSDATA array.
srvet_claudio wrote: Wed Jun 01, 2016 12:40 am I will include
In this case, Claudio you already idealized how to do ?
Would you include it in the h_grid.prg code by adding aValidMessages as in h_browse.prg?

One idea only:
Perhaps this message could controlled by an optional thru the SET command at boolean variable working as a flag that could be interpreted when the HMG's message can be used or when the user's message been desired as preference. What do you think ?