I try to implement a grid where an edited cell behave as follow:
- before exiting an edited cell, the grid check if this cell match some constraints.
- If the value match the constraints you can leave the cell.
- if the value doesn't match the constraints, the cell MUST keep the focus.
On the CellValidate event, I have this code :
//------------------------------------------------------------------------------
procedure TForm2.GridCellValidate(Sender: TObject; ACol, ARow: Integer;
var Value: string; var Valid: Boolean);
//------------------------------------------------------------------------------
var
i:Integer;
begin
if Value='' then valid:=True
else begin
i:=StrToInt(value);
case aRow of
0: Valid:= (i mod 2)=0;
1: Valid:= (i mod 2)=1;
end;
end;
end;
Which set valid to True if you type an even value for row 0 and an odd value for row 1.
When I try to leave my edited cell with Up/down key and this code set Valid variable to False. The Cell keep the focus and I remain in the cell.
But If i click into another cell, and Valid is false, my grid cancel the edit AND exit the cell.