Fórum Problema em ordenar DBGrid no delphi #607721

24/01/2020

0

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

Responder

Posts

25/01/2020

Dirceu Morais

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.
Responder

Gostei + 0

30/01/2020

Douglas

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...
Responder

Gostei + 0

03/02/2020

Anderson Gonçalves

select * from TABELA
order by CAMPO desc
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar