Board index » delphi » finding record number of a DBTable when the scroll bar in a DBGrid is clicked

finding record number of a DBTable when the scroll bar in a DBGrid is clicked

I am trying to work out how to find the record number of a table when
the scroll bar in a dbgrid that is linked to the dbtable through a
dbdatasource is clicked.

I have tryed all of the onmouse events but they don't get activated
when the scrollbar is clicked.

Any help would be appreciated.

 

Re:finding record number of a DBTable when the scroll bar in a DBGrid is clicked


This is a multi-part message in MIME format.
--------------76DB91B1BFA5FDCB1DEDED25
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit

Hi,

I would use the OnDataChange event of the datasource of the dbtable.
Though, you have to be careful when you use it because it is activated
when the  State property changes.  Try it, it might achieve what you
want!

Cheers/Amjad

Quote
Stuart Reid wrote:
> I am trying to work out how to find the record number of a table when
> the scroll bar in a dbgrid that is linked to the dbtable through a
> dbdatasource is clicked.

> I have tryed all of the onmouse events but they don't get activated
> when the scrollbar is clicked.

> Any help would be appreciated.

--------------76DB91B1BFA5FDCB1DEDED25
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Amjad Hanouneh
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Amjad Hanouneh
n:              Hanouneh;Amjad
org:            Nassar Investment Company Ltd.
adr:            Bethlehem Rd.;;P.O. Box 620;Bethlehem;West Bank;;
email;internet: n...@p-ol.com
title:          Computer IS Manager
tel;work:       972-2-74-4061
tel;fax:        972-2-74-3342
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
end:            vcard

--------------76DB91B1BFA5FDCB1DEDED25--

Re:finding record number of a DBTable when the scroll bar in a DBGrid is clicked


Assuming the grid is connected to a TTable you can use TTable.RecNo to
get the current record number.

Bill

(Sorry but TeamB cannot answer support questions received via email.              )
(To send me email for any other reason remove .nospam from my address.)

Re:finding record number of a DBTable when the scroll bar in a DBGrid is clicked


Quote
> Assuming the grid is connected to a TTable you can use TTable.RecNo to
> get the current record number.

That's not a problem...the problem is when I am using a scroll bar in
a dbgrid, there doesn't seem to be an event that gets triggered when
either of the arrows on the vertical scroll bar on the dbgrid are
clicked to change the record. As far as I can tell, I have tryed all
of the events on the ttable, the datasource and the dbgrid.

Re:finding record number of a DBTable when the scroll bar in a DBGrid is clicked


Hello Geoff,

I detect record "scrolls" in my app by using the OnDataChange property
of a DataSource.  The trick is using the Field parameter to the event in
conjuction with State property of the TTable or TQuery.  If the user
changes one field in a record then Field will point to the TField object
that was changed and the State will no longer be dsBrowse.  If, however,
a whole bunch on fields changed at the same time (i.e. moving to a
different record) then the Field parameter will be nil. Now if the State
is dsBrowse you know that the user did not change any field in the
current record so the user must have moved to a different record.
Example:

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  If (Field = nil) and (Table1.State = dsBrowse) Then
    //moved to different record
end;

Hope this helps,
Mike

Re:finding record number of a DBTable when the scroll bar in a DBGrid is clicked


In D3 you could try the BeforeScroll and AfterScroll events of TTable.
The only other alternative is TDataSource.OnDataChange.

Bill

(Sorry but TeamB cannot answer support questions received via email.              )
(To send me email for any other reason remove .nospam from my address.)

Re:finding record number of a DBTable when the scroll bar in a DBGrid is clicked


You can pick up a freeware component at the Super Site called dbrecnum.  It
works wonders.
--
Ben
Arrow Software

Geoff Cutler <cutl...@pag.com.au> wrote in article
<3457a85d.18869...@forums.borland.com>...

Quote
> > Assuming the grid is connected to a TTable you can use TTable.RecNo to
> > get the current record number.

> That's not a problem...the problem is when I am using a scroll bar in
> a dbgrid, there doesn't seem to be an event that gets triggered when
> either of the arrows on the vertical scroll bar on the dbgrid are
> clicked to change the record. As far as I can tell, I have tryed all
> of the events on the ttable, the datasource and the dbgrid.

Other Threads