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.
*--------------------------------