Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to sort a TStringGrid using the Bubblesort algorithm Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
05-Nov-02
Category
VCL-General
Language
Delphi 2.x
Views
84
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Does anyone know an easy way to sort TStringGrids, preferably by the first column?

Answer:

Here is a quick Bubblesort:

1   procedure TForm1.Button1Click(Sender: TObject);
2   var
3     pass, j: integer;
4     hold: TStringList;
5   begin
6     hold := TStringList.Create;
7     {sorting is based on first column, '0'}
8     for pass := 1 to StringGrid1.RowCount - 1 do
9     begin
10      for j := 0 to StringGrid1.RowCount - 2 do
11        if StringGrid1.Cells[0, j] > StringGrid1.Cells[0, j + 1] then
12        begin
13          hold.Assign(StringGrid1.Rows[j]);
14          StringGrid1.Rows[j].Assign(StringGrid1.Rows[j + 1]);
15          StringGrid1.Rows[j + 1].Assign(hold);
16        end;
17    end;
18    hold.Free;
19  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC