Recent

Author Topic: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back  (Read 4119 times)

Fripsy

  • New Member
  • *
  • Posts: 14
Hi All,

I'm adding grouped lines in a stringgrid through the OnDrawCell event, I'm not creating a new component (yet).
I use the first column (0) as storage for the row's settings.

The grouped lines work fine (kinda like merge fields), so I decided to make those groups collapsable and expandable.
As there is no "RowHide" function, I do something like this in the OnDrawCell routine:

Code: [Select]

      if (Sender as TStringGrid).Cells[0, aRow] = 'Hidden' then
      begin
        (Sender as TStringGrid).RowHeights[aRow] := 0;
        (Sender as TStringGrid).Canvas.FillRect(aRect);
      end
      else
      begin
        (Sender as TStringGrid).RowHeights[aRow] := (Sender as TStringGrid).DefaultRowHeight;
        (Sender as TStringGrid).Canvas.FillRect(aRect);
      end;


The problem is, that once set RowHeights[aRow] to 0 (to hide the row), there is now way to set it back to normal: the row will not display.
If I set RowHeights[aRow] to 1, it works, but I get a 1px line for every row, which isn't "estétique"...

I already searched the grid.pas for a way to solve this, but I can't seem to find why this is happening.
I hope someone can shed a light on this.

Thanks,
Frank.
Lazarus 1.4.0 r48774 FPC 2.6.4 i386-win32-win32/win64

Fripsy

  • New Member
  • *
  • Posts: 14
Re: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back
« Reply #1 on: April 26, 2015, 11:44:50 am »
Just upgraded from Lazarus 1.2.6 to 1.4, same problem  %)
Lazarus 1.4.0 r48774 FPC 2.6.4 i386-win32-win32/win64

zeljko

  • Hero Member
  • *****
  • Posts: 1764
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back
« Reply #2 on: April 26, 2015, 01:00:05 pm »
Open an issue about it and attach example project.

Fripsy

  • New Member
  • *
  • Posts: 14
Re: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back
« Reply #3 on: May 01, 2015, 01:17:16 pm »
Thanks zeljko, just added it to the bugtracker.
Lazarus 1.4.0 r48774 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6760
Re: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back
« Reply #4 on: May 01, 2015, 02:04:27 pm »
Thanks zeljko, just added it to the bugtracker.
May I ask why you consider this a bug?

You want to "reset" the height of a row in its own OnDrawCell.
But for rows with a height of 0 the OnDrawCell is never called.
(so you can't do it in that event)

Look in Grids.pas for TCustomGrid.DrawRow(aRow: Integer);
There you can see the procedure ends when R.Top>=R.Bottom (which is true for Rows of 0 height).

When you add a button for example with the code to reset the rowheight manually you see it works.

So this is not really a bug but a design-fault.

Fripsy

  • New Member
  • *
  • Posts: 14
Re: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back
« Reply #5 on: May 01, 2015, 06:40:14 pm »
Hi rvk,

You're right, it is logical that the OnDrawCell is never called with a height of 0.
Sorry that I didn't think this through...

I wanted to delete the issue in the bugtracker but I can't seem to find it anymore...

Meanwhile, I created a workaround by commenting out the "exit" in the DrawRow procedure in grid.pas, and forcing a repaint of the grid.
This seems to work fine for the moment.

Thanks,
Frank.
Lazarus 1.4.0 r48774 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6760
Re: [TStringGrid] RowHeights[aRow] set to 0: impossible to change back
« Reply #6 on: May 01, 2015, 11:14:08 pm »
I wanted to delete the issue in the bugtracker but I can't seem to find it anymore...
It's still on the first page in the bugtracker. (the bugtracker for Lazarus, that is, link in the bar at the left of the main forum-page)
http://bugs.freepascal.org/view.php?id=28005

Quote
Meanwhile, I created a workaround by commenting out the "exit" in the DrawRow procedure in grid.pas, and forcing a repaint of the grid.
This seems to work fine for the moment.
That is a workaround, yeah. But it seems kind of "hacky". I take it you will eventually change this and use some other way. I don't know what code changes the string in the stringgrid back from Hidden to something else but you could create a function (or class helper) changecell(X,Y: Integer; Value: String); and check in that function if the row should be visible or not. But it kind of all depends your design.

 

TinyPortal © 2005-2018