Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Highlighted DBGrid entries, getting first & last...

Posted on 1997-11-05
2
Medium Priority
?
173 Views
Last Modified: 2010-04-04
Hi!

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 : )

Pegasus
My question is this.

0
Comment
Question by:Pegasus100397
2 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 640 total points
ID: 1349565
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
begin
  Find(Items[I],J);
  Bookmark:=items[I];
  Edit;
  //do something with the current selected record
  Post;
end;

//to find the last selected record do the following:
with DBGrid.SelectedRows, Table1 do
begin
  Find(Items[Count-1],J);
  Bookmark:=items[Count-1];
  Edit;
  //do something with the last selected record
  Post;
end;
0
 
LVL 3

Author Comment

by:Pegasus100397
ID: 1349566
Ronit,

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!
Pegasus
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question