Problema em ordenar DBGrid no delphi

Delphi

24/01/2020

sou meio novato no Delphi sei o básico...

E estou com problema ao ordenar os cadastros com ASC ou DESC.

No Banco de dados estou utilizando (IBQuery)+(UpdateSQL)+(DataSourse)
Douglas

Douglas

Curtidas 0

Respostas

Dirceu Morais

Dirceu Morais

24/01/2020

No evento ontitleclick do dbgrid coloque:

Begin 
   sua_tabela.IndexDefs.Update; 
  if sua_tabela.IndexName = Column.FieldName + '_ASC' then 
   begin 
      sIndexName := Column.FieldName + '_DESC'; 
      Options := [ixDescending]; 
   end 
   else 
   begin 
      sIndexName := Column.FieldName + '_ASC';  
      Options := []; 
   end; 
   if sua_tabela.IndexDefs.IndexOf(sIndexName) < 0 then 
      sua_tabela.AddIndex(sIndexName, Column.FieldName, Options); 
   sua_tabela.IndexName := sIndexName;
end; 



Tente assim.
Não testei.
GOSTEI 0
Douglas

Douglas

24/01/2020

No evento ontitleclick do dbgrid coloque:

Begin 
   sua_tabela.IndexDefs.Update; 
  if sua_tabela.IndexName = Column.FieldName + '_ASC' then 
   begin 
      sIndexName := Column.FieldName + '_DESC'; 
      Options := [ixDescending]; 
   end 
   else 
   begin 
      sIndexName := Column.FieldName + '_ASC';  
      Options := []; 
   end; 
   if sua_tabela.IndexDefs.IndexOf(sIndexName) < 0 then 
      sua_tabela.AddIndex(sIndexName, Column.FieldName, Options); 
   sua_tabela.IndexName := sIndexName;
end; 



Tente assim.
Não testei.




Tentei esse código mas ele não identifica o IndexName , sIndexName, IndexDefs, nem Options...
GOSTEI 0
Anderson Gonçalves

Anderson Gonçalves

24/01/2020

select * from TABELA
order by CAMPO desc
GOSTEI 0
POSTAR