A cell is validated twice, if
- cell value is changed and editing is finished with enter key
- CellValidate shows message box and returns with Valid parameter set to false.
To reproduce, put a AdvStringGrid on a form, assign FormCreate to then form's OnCreate Event, assign AdvStringGrid1CanEditCell to the grid's OnCanEditCell Event, assign AdvStringGrid1CellValidate to the grid's OnCellValidate event and add the following code. Then, change the cell with value 200 (i.e. to value 220) and press the enter key. The message box will be shown twice.
procedure TForm1.AdvStringGrid1CanEditCell(Sender: TObject; ARow, ACol: Integer;
var CanEdit: Boolean);
begin
CanEdit := ACol = 0;
end;
procedure TForm1.AdvStringGrid1CellValidate(Sender: TObject; ACol,
ARow: Integer; var Value: string; var Valid: Boolean);
begin
if ACol = 0 then
begin
MessageDlg('invalid value', mtWarning, [mbOk], 0);
Valid := False;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AdvStringGrid1.FixedCols := 0;
AdvStringGrid1.OnCanEditCell := AdvStringGrid1CanEditCell;
AdvStringGrid1.OnCellValidate := AdvStringGrid1CellValidate;
AdvStringGrid1.Cells[0, 1] := '200';
end;