Forum > LCL

[CLOSED] Merge cells (Stringgrid)

(1/1)

pcurtis:
I found this code to merge cells. It half works, but the cells under the spanned cells are still selecable and the grid lines are visible.

How can I fix this?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;  aRect: TRect; aState: TGridDrawState);var  i, x, y: Integer;begin  if gdFixed in aState then    Exit;  if not (ARow in [1, 3]) then    Exit;  {Draw row 1 with text from cell 1,1 spanning all cells in the row}  with Sender as TStringGrid do  begin    {Extend rect to include grid line on right, if not last cell in row}    if aCol < Pred(ColCount) then      aRect.Right := aRect.Right + GridlineWidth;    {Figure out where the text of the first cell would start relative to the                        current cells rect}    y := aRect.Top + 2;    x := aRect.Left + 2;    for i := 1 to aCol - 1 do      x := x - ColWidths[i] - GridlineWidth;    {Paint cell pale yellow}    Canvas.Brush.Color := $7FFFFF;    Canvas.Brush.Style := bsSolid;    Canvas.FillRect(aRect);    {Paint text of cell 1,1 clipped to current cell}    Canvas.TextRect(aRect, x, y, 'A rather long line which will span cells');  end;end;  

wp:
See the demo project in folder examples/gridexamples/merged_cells of your Lazarus installation.

pcurtis:
Thanks for the pointer.
Turned mcgrid into a component and it works great.

Navigation

[0] Message Index

Go to full version