Einzelnen Beitrag anzeigen

Melmier

Registriert seit: 22. Sep 2012
3 Beiträge
 
#1

Stringgrid sortieren

  Alt 22. Sep 2012, 12:05
Guten Tag,

da ich nicht mehr weiterkomme hoffe ich hier Hilfe zu finden. Mein Problem ist, eine Stringgrid nach Größe der Integer der festgelegten zu sortieren (soweit kein Problem), aber den Skript den ich benutze sortiert nur nach dem ersten Wert der Variable, also von z.B. "15" liest dieser nur die "1" ein, und somit ist "15" weniger als "3", da "3" größer ist als "1".
Ich möchte, dass in der Tabelle die "15" vor der "3", "5", oder "8" steht.
Ich weiß dass es immer ärgerlich ist einen fertigskript zu verwenden, und andere zu bitten diesen zu überschauen, vor allem weil dies enorm zeitaufwändig ist. FAlls irgendjemand trotzdem bereit wäre, wäre ich enorm dankbar! Im folgendem der Skript (von mir auch schon leicht angepasst, wegen auf- und abwärtssortierung):

Zitat:
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 := (CountItem-1) Downto 1 Do
GenStrGrid.Rows[GenStrGrid.Rowcount-J].Text := MyList.Strings[(J - 1)];
end;
finally
//Free the List
MyList.Free;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
// Sort the StringGrid1 on the second Column
// StringGrid1 nach der 1. Spalte sortieren
SortStringGrid(StringGrid1, 1);
end;


Schon im voraus, vielen Dank für jeden der sich die Mühe macht das allein durchzulesen, Entschuldigung für etwaige Fehler.
  Mit Zitat antworten Zitat