他の例が見つからなかったため、Firemonkey Stringgrid をソートする私の基本的な試み。これを最適に達成するための最適化やその他の提案を歓迎します。私のコードは基本的に、ソートするために選択された列を取得し、そのソート順で他の列を完成させます:
procedure TfrmMain.StringGridSort(StrGrid: TStringGrid; SortColumn: Integer);
var
col, row, rowx: Integer;
MySortCol, MyListCols: TStringList;
begin
MySortCol := TStringList.Create;
MyListCols := TStringList.Create;
try
MySortCol.Sort;
MyListCols.Sorted := False;
StrGrid.BeginUpdate;
try
for row := 0 to StrGrid.RowCount - 1 do
MySortCol.AddObject(StrGrid.Cells[SortColumn, row], TObject(row));
MySortCol.Sorted := True;
for row := 0 to StrGrid.RowCount - 1 do
StrGrid.Cells[SortColumn, row] := MySortCol[row];
for col := 0 to StrGrid.ColumnCount - 1 do
if col <> SortColumn then
begin
MyListCols.Clear;
for row := 0 to StrGrid.RowCount - 1 do
MyListCols.Add(StrGrid.Cells[col, row]);
for rowx := 0 to StrGrid.RowCount - 1 do
StrGrid.Cells[col, rowx] :=
MyListCols[Integer(MySortCol.Objects[rowx])];
end;
finally
StrGrid.EndUpdate;
end;
finally
MySortCol.Free;
MyListCols.Free;
end;
end;
前もってありがとうポール