Ver Mensaje Individual
  #7  
Antiguo 25-03-2016
Avatar de pnsd_89
pnsd_89 pnsd_89 is offline
Miembro
 
Registrado: mar 2007
Posts: 112
Reputación: 18
pnsd_89 Va por buen camino
Buenas yo uso un DBGridEh con DBxpert logro ordenar con el siguiente codigo:

Código Delphi [-]
procedure OrdenaDataSetGridEH(var CDS: TClientDataSet; Column: TColumnEH; var dbgPrin: TDBGridEH);
const
  idxDefault = 'DEFAULT_ORDER';
var
  strColumn : string;
  i : integer;
  bolUsed : boolean;
  idOptions : TIndexOptions;
begin

  strColumn := idxDefault;
  if Column.Field.FieldKind in [fkCalculated, fkLookup, fkAggregate, fkInternalCalc] then Exit;
  if Column.Field.DataType in [ftBlob, ftMemo] then Exit;
  //
  //for i := 0 to dbgPrin.Columns.Count -1 do
    //dbgPrin.Columns[i].Title.Font.Style := [];
  for i := 0 to dbgPrin.Columns.Count -1 do
    dbgPrin.Columns[i].Title.Font.Color := clNavy;

  //
  bolUsed := (Column.Field.FieldName = CDS.IndexName);
  //
  CDS.IndexDefs.Update;
  for i := 0 to CDS.IndexDefs.Count - 1 do
  begin
    if CDS.IndexDefs.Items[i].Name = Column.Field.FieldName then
    begin
      strColumn := Column.Field.FieldName;
      case (CDS.IndexDefs.Items[i].Options = [ixDescending]) of
         True : idOptions := [];
         False : idOptions := [ixDescending];
      end;
    end;
  end;
  //
  if (strColumn = idxDefault)  or (bolUsed) then
  begin
    if bolUsed then
      CDS.DeleteIndex(Column.Field.FieldName);
    try

      {Esto evita un error de Key Violation}
      if (idOptions <> [ixDescending])
      and (idOptions <> []) then
        idOptions := [];

      CDS.AddIndex(Column.Field.FieldName, Column.Field.FieldName, idOptions,'', '', 0);
      strColumn := Column.Field.FieldName;
    except
      if bolUsed then strColumn := idxDefault;
    end;
  end;
  //
  try
    CDS.IndexName := strColumn;
    Column.Title.Font.Color := clRed;
    Column.Title.Caption := Column.Title.Caption;
    Column.Title.Font.Style := [fsbold];
    CDS.First;
  except
    CDS.IndexName := idxDefault;
  end;
  //
end;

Ahora cuando a un CDS le creo un campo de tipo lookup el mismo no lo ordena y realmente ya he mirado mucho y no logro entender el porque
Responder Con Cita