Lazarus

Programming => Packages and Libraries => FPSpreadsheet => Topic started by: Z80 on March 21, 2022, 08:40:52 pm

Title: [Solved] WorksheetGrid ... the rows collapse
Post by: Z80 on March 21, 2022, 08:40:52 pm
Hello again.

In my little spreadsheet application I am applying a filter to the data to be visible in sWorksheetGrid1.
To test that I made a little code like this:
Code: Pascal  [Select][+][-]
  1.   Form2:=TForm2.Create(Nil);
  2.   Form2.ShowModal;
  3.   If (Form2.ComboBox1.ItemIndex<0) OR (Form2.Edit1.Text='') then exit;
  4.     case Form2.ComboBox1.ItemIndex of
  5.     0: Begin { Prj }
  6.        Krit:=StrToInt(Form2.Edit1.Text);
  7.          For n:=1 to GetLastRow(InSh) do
  8.          begin
  9.          Value:=InSh.ReadAsNumber(n,Prj);
  10.            if (Value=Krit) then Form1.sWorksheetGrid1.ShowRow(n)
  11.                            else Form1.sWorksheetGrid1.HideRow(n);
  12.          end;
  13.        end;
  14.     1: begin showmessage('1') end;
  15.     2: begin showmessage('2') end;
  16.     otherwise
  17.       showmessage('Error');
  18.     end;
  19.   Form2.Free;

Basically it works. At least first time - but when I operate a second time with another criterium (Krit variable) the row height seems to collapse as can be seen in attached png. If I save the workbook I can see that all the data is there and the rows not matching the criteria are hidden. All as supposed.

So I assume that it is a presentation/WorksheetGrid issue.

Any help in solving this is appreciated.
Title: Re: WorksheetGrid ... the rows collapse
Post by: Z80 on March 21, 2022, 10:53:33 pm
I did another little test. where I after a filtering og the sWorksheetGrid1 contents added this code:
Code: Pascal  [Select][+][-]
  1. For n:=1 to GetLastRow(InSh) do sWorksheetGrid1.ShowRow(n);
Result is in attached png. The rows which were not initially hidden are unchanged, the rows that have been hidden are collapsed. As if font had zero height.
Title: Re: WorksheetGrid ... the rows collapse
Post by: Z80 on March 22, 2022, 08:54:48 am
I work with an ods file. Are some of the other formats better for keeping things in control? Actually I also have troubles getting the cell protection work in this application. Is csv a better fileformat to work on? It stores nothing but data. I wouldnt mind do the formatting, protection etc in Lazarus on startup.
Title: Re: WorksheetGrid ... the rows collapse
Post by: wp on March 22, 2022, 11:01:09 am
Open the file fpsvisualutils.pas in folder source/visual of your FPSpreadsheet installation and find the implementation of the function RichTextHeight. Remove the first instruction which is
Code: Pascal  [Select][+][-]
  1.   if (ARect.Left = ARect.Right) or (ARect.Top = ARect.Bottom) then
  2.     exit(0);  

At the moment I don't know whether removing these lines has any side-effects. Therefore, please test carefully (you seem to be one of the few users showing and hiding rows) and report issues related to row heights.
Title: Re: WorksheetGrid ... the rows collapse
Post by: Z80 on March 22, 2022, 10:59:58 pm
The fix works - whatever the reasons are for its necessity.
Thank you very much.
Title: Re: WorksheetGrid ... the rows collapse
Post by: wp on March 22, 2022, 11:17:19 pm
whatever the reasons are for its necessity.
A row in hidden state has zero height. When this row should become visible again, the grid must recalculate the height of this row. But the mentioned condition bypassed cell height calculation in case of zero cell height.

Probably there is a better solution since the worksheet row record still contains the row height that had been valid before the row was hidden. Therefore this entire step should be handled differently. But at the moment I don't have the time to work through all the details...
Title: Re: [Solved] WorksheetGrid ... the rows collapse
Post by: Z80 on March 30, 2022, 12:25:30 am
Behavior and fix is similar in windows and linux regarding this.
TinyPortal © 2005-2018