lisa andrews markitks
lisa andrews markitks

Reputation: 127

Compare value in the previous cell StringGrid

When I finish entering the value in a cell of the TStringGrid I need to check if it is greater than the value that is in the cell of the previous column, on the same line ... if it inserts otherwise it will delete enter image description here

in this case the 20% would not be inserted because it is smaller

I tried to make the comparison in this way but it triggers this method every time I type and not when I lose focus

  procedure TfrmConfiguraClassificacao.listaFaixasSetEditText(Sender: TObject;
  ACol, ARow: Integer; const Value: string);
begin
if Acol=1 then
    //check if it is larger
end;

Upvotes: 0

Views: 405

Answers (1)

LU RD
LU RD

Reputation: 34899

You can validate the cell when the user moves to another cell (OnSelectCell) or when focus shifts to another control (OnExit).

Use the OnSetEditText event to store the last edited cell location.

Something along these lines:

Type
  TfrmConfiguraClassificacao = Class(TForm)
    ...
  private
    fCol,fRow : Integer;
    function CellValidated : Boolean;
  ...
  end;

...

procedure TfrmConfiguraClassificacao.listaFaixasEnter(Sender : TObject);
begin  // Initialize edited cell location
  fCol := -1;
  fRow := -1;
end;

procedure TfrmConfiguraClassificacao.listaFaixasSetEditText(Sender: TObject;
  ACol, ARow: Integer; const Value: string);
begin  // Save the edited cell location
  fCol := ACol;
  fRow := ARow;
end;

procedure TfrmConfiguraClassificacao.listaFaixasSelectCell(Sender : TObject;  
  ACol, ARow: Longint; var CanSelect: Boolean);
begin  // Validate edited cell location
  CanSelect := CellValidated;
end;

procedure TfrmConfiguraClassificacao.listaFaixasExit(Sender : TObject);
begin  // Validate edited cell location
  if not CellValidated then
    // Handle focus redirection
end;

function TfrmConfiguraClassificacao.CellValidated : Boolean;
begin
  Result := True;
  if fCol=1 then begin
    // if not larger, handle it and set Result to false
  end;
end;

Upvotes: 1

Related Questions