Iterating through rows in a DBGrid


I have a DBGrid on a form with MultiSelect set to true.  When the user selects various rows and clicks a button, I want to add up the values in one of the columns.  I have no problem isolating the column involved, but how do I iterate through the selected rows?

(I tried making a derivative of the RxDBGrid which has a protected procedure GotoSelection(Index).  I tried to publish it, but got the error "unsatisfied forward declaration")

Any help would be appreciated.


Who is Participating?
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.

Hi john,

To do this that you want I used a TTable (Table1) and a TDBGrid (DBGrid1).

I put this code below in a Button and it worked very well.

I hope that you enjoy,


procedure TForm1.BitBtn1Click(Sender: TObject);
var a:integer;
  if DBGrid1.SelectedRows.CurrentRowSelected then
    for a:=0 to DBGrid1.SelectedRows.Count-1 do begin
      Table1.Bookmark := DBGrid1.SelectedRows.Items[a];
      Table1.FieldByName('Field1').Value := Table1.FieldByName('Field1').Value+2;


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
jdthedjAuthor Commented:
Thanks Fulvio.  I appreciate your help.
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.