Board index » delphi » TDBGrid

TDBGrid

I am using Delphi 3.0 and Interbase 5.0.  I displayed my data on a TDBGrid
with dgMultiSelect sets to TRUE.  When the user highlights the record(s) in
the grid, I will call TDBGrid.SelectedRows.CurrentRowSelected method in a
while-loop to check if a specific record is selected.  However, even a
record is selected on the grid, the CurrentRowSelected method will return
FALSE. But sometimes it will return TRUE after it first return FALSE on a
highlighted record.

Any hints?

Thanks.

Ada

 

Re:TDBGrid


Quote
> FALSE. But sometimes it will return TRUE after it first return FALSE on a
> highlighted record.

Are you testing during the OnDrawCell Event or OnDrawDataCell?

If you are, then the drawing mechanism moves the record pointer to UnSelect
Draw the previously selected record and moves to draw the currently
selected record. You need to use the field passed to these events to
determine if the record is selected. The field it is currently drawing has
the dataset positioned so you can test any field in the record you want to
determine if it is a particular record you are interested in.  

fwiw
Charles Lam

Re:TDBGrid


In the TDBGrid, I am testing the "TDBGrid.SelectedRows.CurrentRowSelected"
method on OnDblClick event. So, user can highlight multiple records and
then double-click on either one of the highlighted one and on the
OnDblClick event, perform a routine check.  So, do you think I should do
the checking on OnDrawDataCell event instead? If yes, how can I allow user
to select multiple records and then perform a check?

Any idea is appreicated.

Thanks.

Ada

Charles Lam <Char...@tpmco.com> wrote in article
<01bd24e9$d1378ae0$47ca928b@charles-95>...

Quote
> > FALSE. But sometimes it will return TRUE after it first return FALSE on
a
> > highlighted record.

> Are you testing during the OnDrawCell Event or OnDrawDataCell?

Re:TDBGrid


Ada Fung <a...@trams.com> wrote in article
<01bd250c$fcd95a20$0ec7b7ce@ada_nt>...

Quote
> In the TDBGrid, I am testing the

"TDBGrid.SelectedRows.CurrentRowSelected"

Quote
> method on OnDblClick event. So, user can highlight multiple records and
> then double-click on either one of the highlighted one and on the

Ada,

I believe your problem is the DoubleClick.  A DoubleClick always fires a
single click event. In a Grid the single click changes the selected
records. I think your problem would be solved if instead of DoubleClick,
you put a button on the form and do your calculations that way.

I know this is not as efficient as you would like.  The other answer may
lie in testing how in the single click event you can keep your selection. I
do not know off hand if the selection changes before or after the click
event.

Sorry I can't be more help.
Charles Lam

Other Threads