21
Generale / Re:ColumnClickSorts con le Stringgrid
« Ultimo post da alexarmato66 il Maggio 20, 2024, 02:39:59 pm »risolto.Cosi ordino sia decrescente che crescente cliccando sull'intestazione:
Codice: [Seleziona]
procedure TForm1.StringGrid6CompareCells(Sender: TObject; ACol, ARow, BCol,
BRow: Integer; var Result: integer);
var
Val1, Val2: Integer;
begin
if ACol = 0 then
begin
// Convertire le stringhe in numeri interi per la colonna zero
Val1 := StrToIntDef(StringGrid6.Cells[ACol, ARow], 0);
Val2 := StrToIntDef(StringGrid6.Cells[BCol, BRow], 0);
// Confrontare i valori numerici
if Val1 < Val2 then
Result := -1
else if Val1 > Val2 then
Result := 1
else
Result := 0;
end
else
begin
// Utilizzare il confronto predefinito per le altre colonne
Result := CompareStr(StringGrid6.Cells[ACol, ARow], StringGrid6.Cells[BCol, BRow]);
// Se si desidera l'ordinamento decrescente, invertire il risultato
if StringGrid6.SortOrder = soDescending then Result := -Result;
end;
end;