Recent

Author Topic: [SOLVED] Sort StringGrid when Column Title is Clicked by User  (Read 12940 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 714
Hey
I've read http://wiki.lazarus.freepascal.org/Grids_Reference_Page#Sorting_Columns_or_Rows which is useful to learn how to sort a grid by a column when the grid is clicked generally, but what I'm after is to discover how to sort my grid in the same way that spreadhseets do...i.e. if I have Column1, Column 2 and Column3 and I want to sort the user to be able to sort by Column2 if the user clicks the grey title area of Column2. Likewise for Column1 or 3.

Code: [Select]
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
  Stringgrid1.SortColRow(true, 1);  // This sorts by column 2 works when I just click the grid,
  // but how can I sort by column 2 when, and only when, the user clicks the title area of the column?
 
end;
??

Thanks

Ted

« Last Edit: May 05, 2012, 12:32:21 am by tedsmith »
Lazarus 2.0.4 and fpc 3.0.4 - Linux Mint 19 LTS, Windows 10 64 and Mac OSX Catlina
Useful Page to remember : http://wiki.freepascal.org/Cross_compiling#From_Linux_x64_to_Linux_i386

Gizmo

  • Hero Member
  • *****
  • Posts: 714
Re: Sort StringGrid when Column Title is Clicked by User
« Reply #1 on: May 05, 2012, 12:31:54 am »
Just answered this myself...the StringGrid properties has a 'ColumnClickSorts' which I can just set to true.

Amazingly cool.

Thanks
Lazarus 2.0.4 and fpc 3.0.4 - Linux Mint 19 LTS, Windows 10 64 and Mac OSX Catlina
Useful Page to remember : http://wiki.freepascal.org/Cross_compiling#From_Linux_x64_to_Linux_i386

Robot

  • New member
  • *
  • Posts: 6
Re: [SOLVED] Sort StringGrid when Column Title is Clicked by User
« Reply #2 on: May 05, 2012, 03:30:27 am »
property ColumnClickSorts ? are you sure ?
i do'nt find this property in stringgrid.

Gizmo

  • Hero Member
  • *****
  • Posts: 714
Re: [SOLVED] Sort StringGrid when Column Title is Clicked by User
« Reply #3 on: May 09, 2012, 02:37:49 pm »
In v1.1 using FPC 2.6.1+, yes. I have created a second SG and applied the same property.
Lazarus 2.0.4 and fpc 3.0.4 - Linux Mint 19 LTS, Windows 10 64 and Mac OSX Catlina
Useful Page to remember : http://wiki.freepascal.org/Cross_compiling#From_Linux_x64_to_Linux_i386

 

TinyPortal © 2005-2018