Autor Beitrag
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mi 17.11.04 06:39 
Hallo Leute !
Ich habe einen Code,das einen StringGrid aufsteigend sortiert:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
procedure SortStringGrid(var GenStrGrid: TStringGrid; ThatCol: Integer);
const
  // Define the Separator
  TheSeparator = '@';
var
  CountItem, I, J, K, ThePosition: integer;
  MyList: TStringList;
  MyString, TempString: string;
begin
  // Give the number of rows in the StringGrid
  CountItem := GenStrGrid.RowCount;
  //Create the List
  MyList        := TStringList.Create;
  MyList.Sorted := False;
  try
    begin
      for I := 1 to (CountItem - 1) do
        MyList.Add(GenStrGrid.Rows[I].Strings[ThatCol] + TheSeparator +
          GenStrGrid.Rows[I].Text);
      //Sort the List
      Mylist.Sort;
      for K := 1 to Mylist.Count do
      begin
        //Take the String of the line (K – 1)
        MyString := MyList.Strings[(K - 1)];
        //Find the position of the Separator in the String
        ThePosition := Pos(TheSeparator, MyString);
        TempString  := '';
        {Eliminate the Text of the column on which we have sorted the StringGrid}
        TempString := Copy(MyString, (ThePosition + 1), Length(MyString));
        MyList.Strings[(K - 1)] := '';
        MyList.Strings[(K - 1)] := TempString;
      end;
      // Refill the StringGrid
      for J := 1 to (CountItem - 1) do
        GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];
    end;
  finally
    //Free the List
    MyList.Free;
  end;
end;

....kann ich das denn auch machen,dass er ABSTEIGEND sortiert ?

Jagg

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mi 17.11.04 08:31 
Titel: hmm,
anstatt

ausblenden Delphi-Quelltext
1:
GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];					


machste

ausblenden Delphi-Quelltext
1:
GenStrGrid.Rows[J].Text := MyList.Strings[(MyList.count - J)];					


das sollte gehen. Die StringList Funktion Sort selbst kann nur aufsteigend sortieren.

_________________
mfg. Joel
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Do 18.11.04 04:32 
ok danke funktioniert wunderbar...weiss du ob man in stringgrid auch FILTERN kann ???
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Do 18.11.04 08:23 
Jagg hat folgendes geschrieben:
...weiss du ob man in stringgrid auch FILTERN kann ???


?? Wie meinst' dass ?

_________________
mfg. Joel
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Do 18.11.04 19:16 
ich meine in ttables kann ja filtern udn so
mit
ausblenden Quelltext
1:
2:
3:
table1.filtered:= false;
table1.filtere:='wert'
table1.filtered:= true;


geht das auch mit Stringgrids ?

habe eine textdatei und daraus lese ich alles in den stringgrid...