Changing TWebStringGrid RowCount clears the grid

Hi,

TMS WEB Core 2.9.9.2 has introduced what seems to me like a bug: When you change a TWebStringGrid’s RowCount, it clears the entire grid.

This can be reproduced by creating a new web app and adding a TWebStringGrid then adding the following code to the main form create:

procedure TForm1.WebFormCreate(Sender: TObject);
var
  r: integer;
begin
  for r := 0 to WebStringGrid1.RowCount - 1 do
    WebStringGrid1.Cells[1, r] := IntToStr(r);

  WebStringGrid1.RowCount := WebStringGrid1.RowCount + 1;
  r := WebStringGrid1.RowCount - 1;
  WebStringGrid1.Cells[1, r] := IntToStr(r);
end;

Since the TWebStringGrid has 5 rows by default, you’d expect this to give a grid with 6 rows and the numbers 0 to 5 in the 2nd column. Instead you get this:

That is because when the RowCount is changed, the existing contents of the grid are cleared.

I rolled back to version 2.9.9.1 and it doesn’t do this.

Thanks.

I retested this with v3 and code:

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  webstringgrid1.RowCount := 10;
end;

procedure TForm1.WebFormCreate(Sender: TObject);
begin
  webstringgrid1.InitSample(imLinear);
end;

and this works as expected.
I suggest to try v3 that is available for download on your "My Products" page.

Hi,

I finally got around to trying v3 and, while it fixes the problem I reported above, there are still issues (which are also in 2.9.9.2) with it clearing other contents and formatting when a row is added.

Here is my new test code:

procedure TForm1.WebFormCreate(Sender: TObject);
var
  r: integer;
begin
  for r := 0 to WebStringGrid1.RowCount - 1 do
    WebStringGrid1.Cells[1, r] := IntToStr(r);
  WebStringGrid1.AddCheckBox(2, 2, true);
  WebStringGrid1.CellElements[1, 1].style.setProperty('background-color', '#90d190');
  WebStringGrid1.CellElements[1, 2].style.setProperty('text-align', 'right');
  WebStringGrid1.CellElements[1, 3].style.setProperty('border-right-width', '0');
  WebStringGrid1.CellElements[2, 3].style.setProperty('border-left-width', '0');
  WebStringGrid1.CellElements[1, 4].style.setProperty('border-top-width', '2px');
end;

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  WebStringGrid1.RowCount := WebStringGrid1.RowCount + 1;
end;

The grid looks like this (which is as expected) before the button is pressed:


Pressing the button changes it to this:

All the styles and the checkbox are gone.

We traced & solved this issue.
The next update will address this.