Recent

Author Topic: TStringGrid or alternative with merged cells  (Read 3697 times)

upsidasi

  • New Member
  • *
  • Posts: 31
TStringGrid or alternative with merged cells
« on: July 07, 2021, 03:41:09 pm »
I'm using a TStringGrid to represent a read-only table. It works like a charm.

Now I'd like to have merged cells like you can achieve in Excel (see attached picture).

Can this be done using TStringGrid?
If no, which component would you recommend?




jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: TStringGrid or alternative with merged cells
« Reply #1 on: July 07, 2021, 04:15:30 pm »
That can be done however, you would need to draw the grid in owner draw and keep track of the merged cells.

when a ItemDraw event takes place, search the list and if the item is the first in its group then you need to expand the drawing rectangle to include the other merged cells to the right and down.

 With now a new resized rectangle you can now draw the merged cells as if they were one cell.

 when the other cells come in for a draw session you first determine if they belong to a ground, if not, then draw it else if they do then determine if the cell is the first upper left , if not, then ignore the drawing and don't allow the inherited code to draw it.
The only true wisdom is knowing you know nothing

upsidasi

  • New Member
  • *
  • Posts: 31
Re: TStringGrid or alternative with merged cells
« Reply #2 on: July 08, 2021, 08:51:36 am »
Thanks for the suggestion.

Can you maybe post a small example here?
Or post a link to a similar case?


Awkward

  • Full Member
  • ***
  • Posts: 150
Re: TStringGrid or alternative with merged cells
« Reply #3 on: July 08, 2021, 09:29:07 am »
what about Lazarus examples?
examples\gridexamples\merged_cells directory

upsidasi

  • New Member
  • *
  • Posts: 31
Re: TStringGrid or alternative with merged cells
« Reply #4 on: July 08, 2021, 09:51:37 am »
Well, just what I needed.
Thanks!

 

TinyPortal © 2005-2018