AdvStringGrid ....correct chain event ...

Hi to all,
i have e new need in my program.
In a form with AdvStringGrid i show the required data without problem.
Now, the new need, i have to let editing in only two columns and validate the input.
Here i have the problems .... more than one.

  1. The editing in rigth column start at normal click or after doubleclick?
    It's unclared because sometime start after first click and sometime start after second (or third) click.
    To reproduce do this: click on non edit cell, after click on editable cells (here somtime edit start at first click and sometime to second), change cell and back .... same as above.
  2. After finish editing start validate event .... and late? Which event is fired? Seem to go back to CanEdit event.
  3. How i can do to stop editing in case on not valid input?

In my program, when the form is open, the grid is NOT focused and the editable columns are, for example, 3 and 5.

here my events ... (SG1 is TAdvStringGrid and column5 is editable only if chckbox Chk2 is false);
This event is fired to enable edit in rigth column, it's fired up with one or double mouse click

procedure TForm1.SG1CanEditCell(Sender: TObject; ARow, ACol: Integer;
  var CanEdit: Boolean);
begin
  if (ACol=3) or ((ACol=5) and Not (Chk2.Checked)) then
  begin
    CanEdit:=True;
  end
  else
  CanEdit:=False;
end;

If is valid i input some text and this is the event to validate

procedure TForm1.SG1CellValidate(Sender: TObject; ACol, ARow: Integer;
  var Value: string; var Valid: Boolean);
begin
  if ACol=3 then
  begin
     Valid:=True;
  end
  else
  if ACol=5 then
  Begin
    // this is valid only if another cell's (4) value is set to 'N'    
    if SG1.Cells[4,ARow]='S' then
    begin
      Valid:=False;
      // No way to exit from cell edit even with "esc" key
    end
    else
    begin
      Valid:=True;
    end;
  end;
end;

There's a way to start edit ONLY after a doubleclick on rigth cell ?

The other option, who i used in other project, is allow edit in onther form and not use inplace edit (that in this case is very appreciate).
Hope you can reproduce this ....

Thank's for attention

Regards
Daniele

  1. How editing starts depends on property settings. Default is that editing starts upon click on a focused/selected cell.
  2. OnCanEditCell is triggered just before editing starts but it can also be triggered to get the readonly state of a cell to draw a cell control disabled for example. OnCanEditCell purpose is to return this readonly state and the sequence of this event triggering should not be relied on.
  3. If you implement OnCellValidate, editing will stop when you set the Valid parameter to true.
  4. There is a property grid.MouseActions.EditOnDblClickOnly that can be used to require a double-click before a cell can be edited.

Hi Bruno,
thank's for your, very, complete reply.
What i misunderstand was the use of "valid" parameter. Now using Value and Valid parameters in a rigth way all works well.
About mousedoubleclick .... i miss grid.MouseActions.EditOnDblClickOnly.

Thank's again for your help.
Regards
Daniele