Trying to do the impossible I think. Newbie question plz help !!!

In a DBGrid I display 2 fields (name and firstname) of a table. I want to have a third field in wich an X appears when I click the field (or disappears). That field does not appear in the tabel, I just use it at runtime in the DBGrid. It's for selecting records in the DBGrid. Afterwards I want to inspect the DBGrid and write the ID's of all seleced records in a new table.
I've tried with a calculated field, but every time I exit the row the X disappears. I tried with ClientDataSet, but since I have no experience at all with Delphi, I doen't really now how to begin.
I also tried just by adding in the DBGrid a new field, but when I try to overwrite the value I get an error.

Plz help.

Thx alot.

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.

Set MultiSelect to true in the Options of the DB Grid, then the users can select multiple lines using Shift or Control and Clicking the necessary lines.

Once that is done, you can loop over the SelectedRows to see what records have been selected.

I'll try to find an example in a minute.


Looping over the SelectedRows can be done like this :

for i := 0 to Pred( DBGrid1.SelectedRows.Count ) do
  { Now you are on a selected row and can do the necessary }

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
Here is sample code directly from one of my apps, with very little modification.  This is doing exactly what you are wanting to do....

procedure TfrmObjMgr.btnInsertIntoPickerClick(Sender: TObject);
 Owner: String;
 ObjName: String;
 ObjectType: String;
 i: Integer;
  // dbg is a dbGrid object
    for i := 0 to dbgSourceObjects.SelectedList.Count-1 do
                       dbgSourceObjects.SelectedList.Items[i] );
      Owner      := tblDBA_OBJECTSOWNER.AsString;
      ObjName    := tblDBA_OBJECTSOBJECT_NAME.AsString;
      ObjectType := tblDBA_OBJECTSOBJECT_TYPE.AsString;
      tblPicked.InsertRecord([Owner, ObjName, ObjectType]);

tblPicked has a dbGrid on the right hand side and tblDBA_OBJECTS has a dbGrid on the left hand side.  The button in question is in the middle and all selected objects from the left hand side are moved to the right hand side grid and table.

This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.