Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for Greece

asked on

TMS DBADVGRID asc,desc the records

I have a tms dbadvgrid and i want when i click to the to a column header of a field to ascending or descending the records.How could i do this?
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Go to the SortSettings property of the grid and set the property Show = true
You can even make it do it on more than one column at a time.
I think this is the property IndexShow = true under SortSettings as well as the first property I mentioned previously.
Avatar of Alex

ASKER

hi mikelittlewood

i did that before ask this question but it does not do anything....
hmm sec let me have a go.
Ive only done it with a normal AdvStringGrid and it works fine.
Avatar of Alex

ASKER

DBADVGRID has many differences with AdvStringGrid and other grids, it is a very complex component...
I wonder whether just because they have inherited the TDBAdvGrid from TAdvStringGrid, the properties are available, but because its linked directly to a query, it can't sort records.
The only thing I can suggest is possibly to trap the sort in the event onCanSort(), and rebuild your query based on which column header was clicked and the current stored direction.
I know it isnt exactly a nice job but its all I can think of.
Seems a bit pointless for the to have written code that cannot be used.
I'll have a look on the TMS component newsgroup and see if anyone else has made a comment on it.
Ok this way a reply to sorting not working for DBAdvGrid

Please see samples BDESort, ADOSort & DBAdvGrid PDF developers guide how to handle sort in a DBAdvGrid with PageMode = true

Avatar of Alex

ASKER

>>>Please see samples BDESort, ADOSort & DBAdvGrid PDF developers guide how to handle sort in a DBAdvGrid with PageMode = true


where i can find it?

Avatar of Alex

ASKER

or could you make me an example about this that you said before?

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The only thing I can suggest is possibly to trap the sort in the event onCanSort(), and rebuild your query based on which column header was clicked and the current stored direction. .....
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ASKER CERTIFIED SOLUTION
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
where i can find it?

Ill see if I can find it anywhere.
Avatar of Alex

ASKER

thanks a lot mikelittlewood i'll try this code tomorrow and i'll expecting you if you find the pdf.

Thank you again.
I found their demo application for ADOSort, and would you believe, it doesn't work he he.
Their BDESort one worked but they came up with the same solution as what I gave you.

One thing that was different which I would use is to ignore the global variable I made and put this at the beginning of the code I provided

  // disable internal sort
  DoSort := False;

  if dbadvgrid1.SortSettings.Direction = sdAscending then
    dbadvgrid1.SortSettings.Direction := sdDescending
  else
    dbadvgrid1.SortSettings.Direction := sdAscending;

  // then put the rest of this
   ADOQuery1.Close;
   sortSQL := 'ORDER BY ' + DBAdvGrid1.Columns[ ACol].FieldName;
   if dbadvgrid1.SortSettings.Direction = sdDescending then
      sortSQL:= sortSQL + '  DESC';
   ADOQuery1.sql.text := cSQL + sortSQL;
   ADOQuery1.Open;
Avatar of Alex

ASKER

hahaha oh my god!!!!

they have the better components all over the world but they haven't any help this is unacceptable...
Avatar of RickJ
RickJ

I use the DBAdvgrid with ADO and sort and it works fine.
One thing you may need to check is that by default the TMS source has a conditional compile that excludes ADO, make sure that you remove/add this.
Avatar of Alex

ASKER

thanks a lot mikelittlewood this is working fine.

Hi RickJ maybe with ado works but i work now with firebird and interbase components and it doesn't sort so easy only with some options it needs something like mikelittlewood code.

Thank you for the posts.