Recent

Author Topic: [Solved] TStringGrid - Cannot access inserted cell from oncellprocess procedure  (Read 1500 times)

glubbish

  • Jr. Member
  • **
  • Posts: 66
I have a stringgrid that has a column that I graph (Yearly).
I insert a new row to the grid, and redo the graph, but the new row does not show.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DataCellProcess(Sender: TObject; aCol, aRow: integer; processType: TCellProcessType; var aValue: string);
  2. begin
  3.   FormChanged := True;
  4.   if ACol = 1 then DrawGraph;
  5. end;  

The data is in the form of currency, which I change to number to graph.
It appears at this point the value in the cell is null.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DrawGraph;
  2. var
  3.   i, j, k:      integer;
  4.   ModifiedName: string;
  5. begin
  6.   i := 0;
  7.   Yearly.Clear;
  8.   Maximum.Clear;
  9.   repeat
  10.     Inc(i);
  11.     Yearly.AddXY(StrToInt(Data.Cells[0, i]), StrToInt(Copy(stringreplace(Data.Cells[1, i], ',', '', [rfReplaceAll]), 2, Pos('.', stringreplace(Data.Cells[1, i], ',', '', [rfReplaceAll])) - 2)));
  12.   until Data.cells[1, i + 1] = '';
  13.  
  14.   i := 2;
  15.   repeat
  16.     Inc(i);
  17.     j            := StrToInt(Data.Cells[0, i]);
  18.     ModifiedName := stringreplace(Data.Cells[3, i], ',', '', [rfReplaceAll]);
  19.     k            := StrToInt(Copy(ModifiedName, 2, Pos('.', ModifiedName) - 2));
  20.     Maximum.AddXY(j, k);
  21.   until Data.cells[3, i + 1] = '';
  22. end;                  

Is there a way I can update the graph (automatically) to show the newly inserted row?
If I insert a second row, then the previous row shows up in the graph (and so on).

PS. Is there any documentation on stringgrid events? I know that the onprocesscell fires when you ctrl-v into the cell, but I cannot find doc that shows this.
Having this kind of doc for all events would be great.
« Last Edit: June 02, 2019, 01:26:43 am by glubbish »

jamie

  • Hero Member
  • *****
  • Posts: 7697
maybe if you call MyStringGrid.repaint;  it might show.
The only true wisdom is knowing you know nothing

glubbish

  • Jr. Member
  • **
  • Posts: 66
Good thought Jamie.
Unfortunately it did not work.
Neither did data.refresh or data.invalidate

I was also unable to fire another event to call the drawgraph procedure.

jamie

  • Hero Member
  • *****
  • Posts: 7697
The striing grid is message driven, you may need to call

Application.ProcessMessage after you issue one of the refresh commands.

Or just call this and allow the Grid to process messages hanging around waiting, because they won't be processed
until you return from what you are doing.
The only true wisdom is knowing you know nothing

glubbish

  • Jr. Member
  • **
  • Posts: 66
Thanks Jamie.
I actually got it to work.

You would never guess how.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DataCellProcess(Sender: TObject; aCol, aRow: integer; processType: TCellProcessType; var aValue: string);
  2. begin
  3.   FormChanged := True;
  4.   Data.Cells[aCol,aRow] := aValue;  <===== This line here!
  5.   if aCol = 1 then DrawGraph;
  6.   DataInput.SetFocus;
  7. end;

 

TinyPortal © 2005-2018