Hola a todos este codigo sirve para ordenar los registros contenidos en un dbgrid al dar click en el titulo de cada columna
procedure TForm1.DBGrid1MouseMove
(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
pt: TGridcoord;
begin
pt:= DBGrid1.MouseCoord(x, y);
if pt.y=0 then
DBGrid1.Cursor:=crHandPoint
else
DBGrid1.Cursor:=crDefault;
end;
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
{$J+}
const PreviousColumnIndex : integer = -1;
{$J-}
begin
if DBGrid1.DataSource.DataSet is TCustomADODataSet then
with TCustomADODataSet(DBGrid1.DataSource.DataSet) do
begin
try
DBGrid1.Columns[PreviousColumnIndex].title.Font.Style :=
DBGrid1.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
except
end;
Column.title.Font.Style :=
Column.title.Font.Style + [fsBold];
PreviousColumnIndex := Column.Index;
if (Pos(Column.Field.FieldName, Sort) = 1) and (Pos(' DESC', Sort)= 0) then
Sort := Column.Field.FieldName + ' DESC'
else
Sort := Column.Field.FieldName + ' ASC';
end;
end;
espero les sea util