It's impossible to edit last column of grid which width is equal or less to sum of widths of all columns (remember, vertival lines separating columns count too as 1 px) by pressing ENTER key. When you double click with mouse, everything is OK.
I've lost half a day for this
Try my little sample
Code: Select all
#include "hmg.ch"
Function Main
local i
private aHeaders, aWidths, aJust
private aRows := {}
private aValid := {}
private aWhen := {}
private aControls := {}
aHeaders := {"Name","Age"}
aWidths := {200, 100}
aJust := { 0,1}
aValid := { {|| DataValidation()}, {|| DataValidation()} }
aWhen := { {|| .t.}, {||.t.} }
aControls := { {"TEXTBOX","CHARACTER"}, {"TEXTBOX","NUMERIC","999"} }
aADD(aRows, {"Simpson", 65 } )
aADD(aRows, {"Mulder",41 } )
aADD(aRows, {"Smart Max", 25} )
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 500 ;
HEIGHT 550 ;
TITLE 'Editable Virtual Grid Test' ;
MAIN
@ 10,10 GRID Grid_1 ;
WIDTH 300 ;
HEIGHT 240 ;
HEADERS aHeaders ;
WIDTHS aWidths;
VALUE {1,1} ;
TOOLTIP 'Editable Grid Control' ;
EDIT ;
COLUMNCONTROLS aControls;
COLUMNVALID aValid;
COLUMNWHEN aWhen;
VIRTUAL ;
ITEMCOUNT len(aRows) ;
ON QUERYDATA OnQuery() ;
JUSTIFY aJust;
CELLNAVIGATION
@ 400, 10 BUTTON B_1 ;
CAPTION "EXPAND GRID +10px";
ACTION SetProperty("Form_1","Grid_1","Width", GetProperty("Form_1","Grid_1","Width")+10) ;
WIDTH 120 ;
HEIGHT 30
END WINDOW
Form_1.Grid_1.EditOption := GRID_EDIT_REPLACEALL
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return
*----------------
function OnQuery
local nRow, nCol
nRow := This.QueryRowIndex
nCol := This.QueryColIndex
if nRow>0 .and. nCol >0
This.QueryData := aRows[nRow,nCol]
endif
return .t.
*-----------------------
function DataValidation
nRow := this.Value[1]
nCol := this.Value[2]
if empty(This.CellValue)
return .f.
endif
aRows[nRow,nCol] := This.CellValue
return .t.