Hi, I may have found a bug in TWebStringGrid.SplitCells. I’ve created a new project and dropped on a TWebStringGrid and 2 TWebButton - one for merge and one for split. This is what the grid looks like initially:
Then I merge the 2 fixed cells in the first column (this works as expected):
Then I attempt to split those cells again:
I think that speaks for itself!
Here is my code:
procedure TForm1.WebFormCreate(Sender: TObject);
var
r, c: integer;
begin
for r := 0 to WebStringGrid1.RowCount - 1 do
for c := 0 to WebStringGrid1.ColCount - 1 do
WebStringGrid1.Cells[c, r] := 'R' + IntToStr(r) + 'C' + IntToStr(c);
end;
procedure TForm1.MergeButtonClick(Sender: TObject);begin
WebStringGrid1.MergeCells(0, 0, 1, 2);
end;
procedure TForm1.SplitButtonClick(Sender: TObject);
begin
WebStringGrid1.SplitCells(0, 0);
end;
We could trace & solve this issue. Next update will address this.
1 Like
Thanks Bruno. While you’re at it…
What I’m trying to do is resize the columns so they fit “exactly” within the control space, so there is no horizontal scrollbar. This is the code I am using:
procedure TForm1.ResizeButtonClick(Sender: TObject);
var
c: integer;
begin
WebStringGrid1.BeginUpdate;
for c := 0 to WebStringGrid1.ColCount - 1 do
WebStringGrid1.ColWidths[c] := 40; // or whatever the calculated width is
WebStringGrid1.EndUpdate;
end;
Now, I don’t know if I am supposed to do this within a begin/end update, but I get some strange results. Here is my starting grid, with the default columns too wide for the control:
Then I press a resize button to make the columns narrower, and I get this:
So, it resized the columns, but the scroll bar is still there.
If I remove the begin/end update then it works as I’d expect (the scroll bar disappears) BUT if I have any horizontally merged cells then I get an error and the last column is not resized:
ERROR
Uncaught TypeError: Cannot read properties of undefined (reading 'style') | TypeError: Cannot read properties of undefined (reading 'style') at Object.SetColWidths
Call stack…
(http://localhost:8080/Project1.js:62752:20) at Object.ResizeButtonClick (http://localhost:8080/Project1.js:70506:29) at Object.cb [as FOnClick] (http://localhost:8080/Project1.js:265:19) at Object.Click (http://localhost:8080/Project1.js:31387:61) at Object.Click (http://localhost:8080/Project1.js:56690:45) at Object.HandleDoClick (http://localhost:8080/Project1.js:30851:31) at HTMLButtonElement.cb (http://localhost:8080/Project1.js:261:26)
at http://localhost:8080/Project1.js [62752:20]
Lastly, if I need to make the columns wider to fill up the width of the control, with the begin/end update in place, it doesn’t seem to be possible to make them wider than the DefaultColWidth (or perhaps the width when they are first created). Removing the begin/end update allows them to get wider.
We further investigated and fixed both cases. Next update will address this.
1 Like