Recent

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

Gizmo

  • Hero Member
  • *****
  • Posts: 831
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 »

Gizmo

  • Hero Member
  • *****
  • Posts: 831
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

Robot

  • Newbie
  • 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: 831
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.

 

TinyPortal © 2005-2018