Lazarus

Programming => LCL => Topic started by: Gizmo on May 05, 2012, 12:27:54 am

Title: [SOLVED] Sort StringGrid when Column Title is Clicked by User
Post by: Gizmo on May 05, 2012, 12:27:54 am
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

Title: Re: Sort StringGrid when Column Title is Clicked by User
Post by: Gizmo 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
Title: Re: [SOLVED] Sort StringGrid when Column Title is Clicked by User
Post by: Robot on May 05, 2012, 03:30:27 am
property ColumnClickSorts ? are you sure ?
i do'nt find this property in stringgrid.
Title: Re: [SOLVED] Sort StringGrid when Column Title is Clicked by User
Post by: Gizmo 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