setting cellformat for cells containing formulas

Hi



I am writing an application using TAdvSpreadGrid in which I need to use two different cell formats on the same sheet, depending on which column the cell is in. Some columns of formulas need a cellformat of %.0f and others need a cellformat of %.1f. However I can't get the cellformat to persist.



If I write something like



with ssFoo do

    begin

      CellFormat := '%.1f';

      Cells[1,1] := '=SUM(R1C2:R1C3)';

      CellFormat := '%.0f';

      Cells[1,2] := '=SUM(R2C2:R2C3)';



the formula in [1,1] gets recalculated with the same cellformat as [1,2].



I've tried setting AutoRecalc to false with no effect.



Can anyone help?



Jeff Gallant



Please use the OnGetFloatFormat event to handle this dynamically.


Example:
procedure TForm6.AdvStringGrid1GetFloatFormat(Sender: TObject; ACol,
  ARow: Integer; var IsFloat: Boolean; var FloatFormat: string);
begin
  if acol = 1 then
    FloatFormat := '%.1f';
  if acol = 2 then
    FloatFormat := '%.0f';
end;

Hi Bruno



Thanks - it seems counter-intuitive that you can't format a cell statically by eg cellformat[x,y]:=<formatstring> but if it can only be done dynamically, so be it.



However, I have another issue along the same lines.



If I put a formula into a cell eg



Cells[0,1]:=='SUM(R2C2:R2C3)'



and then programmatically change the value in eg R2C2, Cells[0,1] doesn't seem to get automatically updated.



However, if, after setting the new value I reset Cells[0,1] to the formula (ie run



Cells[1,2]:=='SUM(R2C2:R2C3)'



again), I get the correct result.



This negates the usefulness of having a formula which, in s normal spreadsheet would automatically update the result dynamically.



Best wishes



Jeff

When you programmatically change the grid, call grid.Recalc; after all your changes are done. (This reduces recalculations when you do multiple updates and call Recalc just once)

Thanks - makes sense.