I'm using c++ builder (rad studio 2009). I'm finding that if I have a TMyQuery Q showing in a TDBGrid with
Q->IndexFieldNames="" and I click a button that programatically sets Q->IndexFieldNames="SomeField" then the current record is not maintained. The new top record becomes the current record but the AfterScroll event is not even triggered despite the change of record.
It only seems to happen if it's the first thing I do when the programme opens and the grid appears. If I scroll the grid before clicking the sort button the record indicator follows the current record to its new position after sorting. Subsequent sorts made on other fields also work as they should.
When sorting is working as it should the current record is often not 'centred' (as happens with the Locate method) after sorting.
Setting TMyQuery IndexFieldNames>"" changes current record
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44
The point is that a just opened table stays in BOF state. Therefore when you set the IndexFieldNames property of this table, the cursor remains on the first record.
In order to solve this problem you should set the first record in the dataset after its opening, like this:
In order to solve this problem you should set the first record in the dataset after its opening, like this:
Code: Select all
Q->Open();
Q->First();