Link to home
Start Free TrialLog in
Avatar of tommykjensen
tommykjensen

asked on

stringgrid sorting

I have a stringgrid in the gui.

How do I sort all the rows when clicking on one of the collumn titles?
Avatar of PeterLarsen
PeterLarsen

I dont remember for sure, but i think this function is included in delphi 6 or 7.

But if it isn't you have to do it yourself.
I dont have the time right now to do a sample, but the idea is to write out the column to a TSTringList and sort i there.
All other data in the same row are also written to a tstringlist (or similar) and saved in the first tstringlist with TStringList.AddObject('Data to be sorted', Pointer-to-the-second-TStringList).
Sort the stringlist - clear the grid - write data back to the grid.


Good luck
Peter
Avatar of tommykjensen

ASKER

Does anybody have an example? I am relatively new to Delphi.

I have Dellphi 6 proff. Soon I will have V7.
Does anybody have an example? I am relatively new to Delphi.

I have Dellphi 6 proff. Soon I will have V7.
Found a solution. How do I close this question?
HI,
You can do it for example that way:
procedure TForm1.BitBtn1Click(Sender: TObject);
var SL: TStringList;
begin
 SL:=TStringList.Create;
 with StringGrid1 do
  begin
    SL.Assign(Rows[1]);
    SL.Sort;
    Rows[1].Assign(SL);
  end;
  SL.Free;
end;
Sincerely,
Nestorua.
Dear expert(s),

A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20556426/Please-refund-points-I-solved-my-problem-myself.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial