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.

Apie.
ApieAsked:
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.

StefaanCommented:
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.

Regards,


Stefaan
0
StefaanCommented:
Looping over the SelectedRows can be done like this :


for i := 0 to Pred( DBGrid1.SelectedRows.Count ) do
begin
  GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
  { Now you are on a selected row and can do the necessary }
end;
0

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
cjm30305Commented:
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);
var
 Owner: String;
 ObjName: String;
 ObjectType: String;
 i: Integer;
begin
  // dbg is a dbGrid object
  dbgSourceObjects.DataSource.DataSet.DisableControls;
    for i := 0 to dbgSourceObjects.SelectedList.Count-1 do
     begin
      dbgSourceObjects.DataSource.DataSet.GotoBookmark(
                       dbgSourceObjects.SelectedList.Items[i] );
      Owner      := tblDBA_OBJECTSOWNER.AsString;
      ObjName    := tblDBA_OBJECTSOBJECT_NAME.AsString;
      ObjectType := tblDBA_OBJECTSOBJECT_TYPE.AsString;
     
      tblPicked.InsertRecord([Owner, ObjName, ObjectType]);
      tblPicked.Refresh;
     end;
    dbgSourceObjects.UnselectAll;
    dbgSourceObjects.DataSource.DataSet.EnableControls;
end;


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.

Cheers.
Jake
0
CleanupPingCommented:
Apie:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
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
Delphi

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.