Highlighted DBGrid entries, getting first & last...


I have a DBGrid attached to a table with about 630,000 entries in the table. The DBGrid is set to multiselect so the user can highlight (tag) any number of entries that interest them.

I can use a loop, starting from the first record and scanning all the entries until I come upon a DBGrid.SelectedRows.CurrentRowSelected to determine if a row is selected or not, but certainly there must be a better way to determine the first and last entries the user selected and just scan the records in between to find out which ones are selected as opposed to scanning the entire table!

The DBGrid component uses TBookmarks to keep track of the records the user selected but the documentation is horrible about TBookmarks. Is there a BookmarkFirst or BookmarkLast something or another to remedy this situation.

I'd appreciate hearing some creative solutions to this seemingly simple problem : )

My question is this.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1. See explanation in the file manuals.txt.
2. example:

var I, J: Integer;

with DBGrid.SelectedRows, Table1 do //the records from the grid
                                      belong to Table1
for I:=0 to Count-1 do //do some actions only on the selected                          records
  //do something with the current selected record

//to find the last selected record do the following:
with DBGrid.SelectedRows, Table1 do
  //do something with the last selected record

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pegasus100397Author Commented:

Thanks for the answer! Solved my problem in 3 lines of code!

Talk about obscure documentation! I've never looked (or known  of Manuals.TXT) but found gobs of stuff in there pertaining to questions I've had. Thanks for turning me on to it. (I'll never say that REAL programmers never read the documentation again!).

Again, thanks for the answer!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.