Error in Virtual Grid with dynamic font

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 3171
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 203 times
Been thanked: 107 times
Contact:

Error in Virtual Grid with dynamic font

Post by mol » Fri May 10, 2019 6:47 am

I found wrong behavior of GRID control when DynamicFont is used.
I want to use editable virtual grid with last column displayed with different font.
Everything goes OK with displaying.
When I edit cell and want to save it in array, This.CellColIndex always returns index of column dynamic font (in my sample last column, but you can test it with another)

Code: Select all

#include "hmg.ch"

Function Main
	public aCellCoordinates := {0,0}
	private aItems := {}

	AADD (aItems, {"Carrot",        5, "A"})
	AADD (aItems, {"Cauliflower",   0, "B"})
	AADD (aItems, {"Corn",         15, "C"})
	AADD (aItems, {"Tomato",        0, "D"})
	AADD (aItems, {"Zucchini",     20, "E"})

	aControls := { NIL, {'TEXTBOX','NUMERIC'}, NIL }
	aValid	:= { {||Grid_1_Valid()}, {||Grid_1_Valid()}, {||Grid_1_Valid()} }
	aWhen	:= { {||Grid_1_When()}, {||Grid_1_When()}, {||Grid_1_When()} }
	aJustify := {  GRID_JTFY_LEFT, GRID_JTFY_RIGHT, GRID_JTFY_CENTER }
   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 600 ;
      HEIGHT 400 ;
      MAIN 

	DEFINE GRID Grid_1
		PARENT Form_1
		ROW 10
		COL 10
		WIDTH 550
		HEIGHT 330
		ITEMS NIL
		HEADERS {'Product','Stock','Supplier'}
		FONTNAME "ARIAL"
		FONTSIZE 12
		WIDTHS {250,150,100}
		ALLOWEDIT .T.
		CELLNAVIGATION .T.
		COLUMNCONTROLS aControls
		COLUMNVALID aValid
		COLUMNWHEN aWhen
		VIRTUAL .T.
		OnQueryData Grid_1_OnQueryData()
		ITEMCOUNT len(aItems)
	END GRID
	
	aFont := ARRAY FONT "Webdings" SIZE 12 BOLD ITALIC
	if MsgYesNo("Do you want to test with Dynamic Font?")
		Form_1.Grid_1.ColumnDYNAMICFONT  (3) := {|| IF ( Form_1.Grid_1.CellEx(This.CellRowIndex,2) == 0, aFont, NIL) }
	endif

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

Return
*--------------------------------
function Grid_1_OnQueryData

	local nRow
	local nCol

	nRow := This.QueryRowIndex
	nCol := This.QueryColIndex

	if nRow>0 .and. nCol >0
		This.QueryData := aItems[nRow, nCol]
	endif
return
*--------------------------------
function Grid_1_Valid
	local nRow
	local nCol

	nRow := This.CellRowIndex
	nCol := This.CellColIndex
	MsgInfo( "Coordinates saved in VALID function: " + hb_valtoexp(aCellCoordinates)+chr(10)+;
		"Actual coordinates: "+hb_valtoexp({nRow, nCol}) )
	aItems[nRow, nCol ] := This.CellValue
 return .t.
*--------------------------------
function Grid_1_When
	
	aCellCoordinates := { This.CellRowIndex, This.CellColIndex }
return .T.
*--------------------------------


User avatar
andyglezl
Posts: 1123
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 32 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 5:13 pm

Yo veo que si se está grabando en el ARRAY lo que hay en el GRID...(o tal vez no entendí tu pregunta)
*-----------------------------------------------------------------------------------------------------------------------------
I see that if you are recording in the ARRAY what is in the GRID ... (or maybe I did not understand your question)


mol.png
mol.png (46.9 KiB) Viewed 125 times
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
andyglezl
Posts: 1123
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 32 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 5:35 pm

OK ya vi el problema
*-----------------------------------
OK I saw the problem
mol.png
mol.png (56.38 KiB) Viewed 121 times
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
andyglezl
Posts: 1123
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 32 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 6:05 pm

Si cambias lo siguiente, funciona OK
*----------------------------------------------------
If you change the following, it works OK

Code: Select all

*--------------------------------
function Grid_1_Valid
	local nRow
	local nCol

	*nRow := This.CellRowIndex
	*nCol := This.CellColIndex
	
	nRow := aCellCoordinates[ 1 ]
	nCol := aCellCoordinates[ 2 ]
	
	MsgInfo( "Coordinates saved in VALID function: " + hb_valtoexp(aCellCoordinates)+chr(10)+;
		"Actual coordinates: "+hb_valtoexp({nRow, nCol}) )
	aItems[nRow, nCol ] := This.CellValue
	MSGDEBUG( aItems )
 return .t.
mol.png
mol.png (66.55 KiB) Viewed 117 times
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
mol
Posts: 3171
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 203 times
Been thanked: 107 times
Contact:

Post by mol » Fri May 10, 2019 9:22 pm

Of course we can use workaround, but this situation is a bug and should be repaired in sources.
I've lost a lot of time to find what's going on

User avatar
andyglezl
Posts: 1123
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 32 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 9:40 pm

Lo siento, yo nunca he modificado algún fuente de HMG...
*----------------------------------------------------------------------------
I'm sorry, I've never modified any source of HMG ...

A quien corresponda:
*---------------------------
To whom it May concern:
mol wrote:
Fri May 10, 2019 9:22 pm
Of course we can use workaround, but this situation is a bug and should be repaired in sources.
I've lost a lot of time to find what's going on
Andrés González López
Desde Guadalajara, Jalisco. México.

Post Reply