Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Ejemplo de Ordenamiento StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=80752)

varuhs 18-07-2006 19:48:14

Ejemplo de Ordenamiento StringGrid
 
Encontre este ejemplo de ordenamiento de un StringGrid y lo he probado y funciona de las mil maravillas.... asi que se los dejo para que lo usen...

Código:

procedure Sortgrid(Grid : TStringGrid; SortCol:integer);
var
  i,j  : Integer;
  temp : TStringList;
begin
Temp:= TStringList.Create;
with Grid
do begin
  for i := FixedRows to RowCount - 2
  do begin
      for j:= i+1 to rowcount-1
      do begin
        if AnsiCompareText(Cells[SortCol, i], Cells[SortCol,j]) > 0
        then begin
              temp.assign(rows[j]);
              rows[j].assign(rows[i]);
              rows[i].assign(temp);
              end;
        end;
      end;
  end;
temp.free;
end;

y en el evento OnMouseUP de la Grilla

Código:

procedure TForm1.StringGrid1MouseUp(Sender: TObject;Button:TMouseButton;Shift: TShiftState; X, Y: Integer);
var
  c : Integer;
begin
with TStringGrid(Sender)
do begin
  if Y <= RowHeights[0]
  then begin
        C:= x div (DefaultColWidth+GridLineWidth);
        SortGrid(TStringGrid(Sender),C);
        end;

  end;

Saludos
Eduardo Valencia López
Santiago - Chile

trysho 20-07-2006 19:00:55

jeje tenia rato de no ver el metodo de burbuja xD


La franja horaria es GMT +2. Ahora son las 15:20:19.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi