Recent

Author Topic: TStringGrid sort indicator  (Read 5348 times)

dbannon

  • Hero Member
  • *****
  • Posts: 1491
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TStringGrid sort indicator
« Reply #15 on: February 03, 2020, 01:54:39 am »
OK, my conclusions are that the TStringGrid sort indicators are broken but I am not willing to log a bug unless someone else (using a current Lazarus) can confirm my results. GAN does not see this problem using 1.8.4. Here is what I have found, possibly due to using Lazarus 2.0.0 thru to 2.0.7  -

  • StringGrid1.Columns[0].Title.ImageIndex applies only to an externally provided image set.  It neither   reflects nor changes the state of the built in green trianges.
  • A green triangle is turned on by a user clicking a header. It can be toggled up or down by repeated clicks on that header or moved to another column by clicking the other columns header but it cannot   be turned off.  Even clean, clear or deleting the columns will not cancel the display of the green triangles.
  • Using external imagelist does not prevent the green, internal indicator from displaying. You get two, often conflicting indicators.

   
In my case I refresh the grid's data from time to time. The data is presorted on what becomes column 1 and while I would prefer to indicate that column 1 is now the sorted against column, I cannot change those green triangles !

So, instead of making the grid display what I want it to, I can may the data I insert agree with what the grid is claiming to be displaying. Yek !

Code: Pascal  [Select][+][-]
  1.  procedure TForm1.PopulateStringGrid(Grid : TStringGrid);
  2. begin
  3.     while Grid.RowCount > 1 do Grid.DeleteRow(Grid.RowCount-1);
  4.     Grid.InsertRowWithValues(Grid.RowCount, ['A Item', 'Z Item']);
  5.     Grid.InsertRowWithValues(Grid.RowCount, ['B Item', 'Y Item']);
  6.     Grid.InsertRowWithValues(Grid.RowCount, ['C Item', 'X Item']);
  7.     // My data is sorted on column 1, if user has not changed that, we do nothing.
  8.     if Grid.SortColumn > -1 then
  9.         Grid.SortColRow(True, Grid.SortColumn);            // Force data to be same as StringGrid claims its displaying
  10. end;
                           

If someone else can confirm this situation, I will log a bug report.

Thanks GAN and HeavyUser for your help here.

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

GAN

  • Sr. Member
  • ****
  • Posts: 323
Re: TStringGrid sort indicator
« Reply #16 on: February 04, 2020, 03:10:29 am »
Quote
If someone else can confirm this situation, I will log a bug report.
Hi dbannon, do it, because nobody else is writting in this thread. Or it's a bug or a new feature of Lazarus 2.0.x  ;)
Seriously, the green arrows are horrible (sorry), so must be a bug.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3

https://searchlazarus.blogspot.com/

apeoperaio

  • Full Member
  • ***
  • Posts: 216
Re: TStringGrid sort indicator
« Reply #17 on: February 04, 2020, 08:35:07 am »
I got a similar issue only using cocoa, see thread https://forum.lazarus.freepascal.org/index.php/topic,48333.0.html
I can disable the green lazarus arrows using:
TStringGrid.ColumnClickSort := False;

Hope it helps.

dbannon

  • Hero Member
  • *****
  • Posts: 1491
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TStringGrid sort indicator
« Reply #18 on: February 04, 2020, 09:36:52 am »
Hey GAN, I just used her Ladyship's laptop, it shows your video perfectly. And leave no doubt what you are getting is very, very different to wha I see on Lazarus 2something

And, interesting, your green arrows are, as you say, very ugly. On 2 series they are much more modest small green triangles. Thats an improvement at least ! But that change may be where our problem started.

Thanks for chiming in apeoperaio, from what you say, you get what you expect from Windows and Linux but experience problems only on Cocoa ?  But I see this on Linux. Are you using the same version of Lazarus on each platform ?

I feel this (what ever 'this' is) needs to be logged but I so don't understand it right now so will do some more testing. I can go to Windows and MacOS as well as my prefered Linux so, I'll add in a  apeoperaio trick and install a 1.8.4, watch this space !

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

apeoperaio

  • Full Member
  • ***
  • Posts: 216
Re: TStringGrid sort indicator
« Reply #19 on: February 04, 2020, 09:52:05 am »
Under cocoa I am using Lazarus 2.0.7 r62571M FPC 3.0.4 x86_64-darwin-cocoa (alpha)
While on Windows and Linux lazarus 1.8.4

dbannon

  • Hero Member
  • *****
  • Posts: 1491
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TStringGrid sort indicator
« Reply #20 on: February 05, 2020, 12:31:07 am »
Under cocoa I am using Lazarus 2.0.7 r62571M FPC 3.0.4 x86_64-darwin-cocoa (alpha)
While on Windows and Linux lazarus 1.8.4

Ah, good (sort of). That confirms its the transition from 1.8.4 to 2.0 that is the problem.

Attached is the demo that I will put in with the bug report.  It makes the point that in the 2.0 series -

* you cannot, programmatically, control the built in, green indicators.
* the built in images look heaps better than in 1.8.4
* if you add your own image list, and use them, when the end user clicks a heading, they may get both indicators displayed.

While its nice not to have to provide your own imagelist, too many applications involve refreshing the data and it may not be sorted in the manner the user has set it to.

(for the record, I have set my app to re-sort new data to whatever the Grid currently thinks it is sorted to : 
Code: Pascal  [Select][+][-]
  1. if Grid.SortColumn > -1 then
  2.         Grid.SortColRow(True, Grid.SortColumn);

)
Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

wittbo

  • Full Member
  • ***
  • Posts: 149
Re: TStringGrid sort indicator
« Reply #21 on: May 12, 2021, 08:30:19 pm »
Perhaps I should start a new topic, but this context is quite precise.

I'm sure, I found the solution. When analyzing the unit grids, one can see, that the behavior of the small green triangle depends on the internal variable FSortColumn. FSortColumn is the number of the column actually sorted, it is -1 if not sorted. Unfortunately the property SortColumn is not writable. I made a check with a copy of the grids unit and modified the property SortColumn as readable AND writable. That's it.

If you set SortColumn to a value of greater or equal 0, the triangle appears, if set to -1, the triangle disappears; changing SortOrder changes the triangle up or down.

The header click routine sets the value of FSortColumn to the column number the user clicked; unfortunately the procedure SortColRow doesn't do so. Therefore the triangle does not appear, when you call SortColRow without clicking into the column header.

I think, it could be a good idea to make few modifications to TCustomGrid:
- property SortOrder: add a setting routine SetSortOrder, which invalidates the grid after setting the value
- property SortColumn: add a setting routine SetSortColumn, which checks the column number and invalidates the grid after setting the value
- Modify SortColRow: add a line    FSortColumn := index;
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.0.12
iMac with MacOS 10.13.6 / Lazarus 2.0.10

 

TinyPortal © 2005-2018