Page 1 of 1

Reverse order

PostPosted: 12 Oct 2016 21:54
by cyracks
Hi,

is it possible to manually set order by which navigator reads records in dataset. Currently it reads records according to position in dataset, but I would like to have reverse order.
For example if dataset holds values 1,2,3 (in that order) navigator works ok. But if dataset holds values 3,2,1 navigator doesn't work as expected, meaning that button next moves to prior record (if value is 3, click on next will move to 2)

I know custom events can be set for button clicks, so for example if button next is clicked code dataset.prior can be executed, but the problem is that buttons are automatically grayed when on the last/first position. So if in reverse order dataset position is on record 3 only "Last" button is active instead of "First".

Regards,
Tomaž

Re: Reverse order

PostPosted: 13 Oct 2016 01:34
by ScottWGast
Have you tried sorting the dataset?

Re: Reverse order

PostPosted: 13 Oct 2016 09:23
by cyracks
That is the problem. From Dataset point of view order of rows is defined based on Dataset.IndexFieldNames or by "order by" directive in SQL statement, so bellow is the same:
Dataset.IndexFieldNames := "Field" Desc
or
Dataset.sql.text := 'select * from Table order by Field desc'

Navigator orders data based on dataset position and I do not see any option that order can be reversed from that in dataset. That means that rows in dataset must be set to ascending order for navigator to work "correctly" (meaning button next will move to higher value not lower).

Re: Reverse order

PostPosted: 13 Oct 2016 12:22
by Jorge Sousa
Hi

The navigator uses the dataset as it is sorted, using TDataSet.First, TDataSet.Previous,TDataSet.Next and TDataSet.Last, etc...

You will never find a navigator that changes the order of the dataset