Board index » delphi » Sorting and searching in diffrent fields?

Sorting and searching in diffrent fields?

Hi!

I'm working on a application where I need to sort the data in a DBGrid

by one field, and searching on another.
The sorting is not so hard, just assigning an index to the indexname
prop.
But what about the searching... the app keeps searching on the field
I'm sorting by...

Please help!

/Andreas...

 

Re:Sorting and searching in diffrent fields?


Hi!

I'm working on a application where I need to sort the data in a DBGrid

by one field, and searching on another.
The sorting is not so hard, just assigning an index to the indexname
prop.
But what about the searching... the app keeps searching on the field
I'm sorting by...

Please help!

/Andreas...

Re:Sorting and searching in diffrent fields?


In <4nt4l3$...@kaon.kuai.se> and...@kuai.se (Andreas Oestlund) writes:

Quote

>Hi!

>I'm working on a application where I need to sort the data in a DBGrid

>by one field, and searching on another.
>The sorting is not so hard, just assigning an index to the indexname
>prop.
>But what about the searching... the app keeps searching on the field
>I'm sorting by...

>Please help!

>/Andreas...

When you sort on a certain index that index is active.  When you search
on an index THAT index is active you can not have two indexes active at
the same time.  The way around this is to search on secondary tTable
then do a findkey on the first table based on the first table index
field value of the second table.  This should be very straightforward.
Say account number is active in the first table.  You want to search on
the customer name.  You open a second tTable for the same file.

Table2.IndexFieldNames := 'CustName';
Table2.Findkey([Edit2.Text]);
Table1.Findkey([Table2.CustNo]);

To the best of my knowledge that is the only method outside of tQuery.

Ben
Arrow

Other Threads