Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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.
0
Apie
Asked:
Apie
  • 2
1 Solution
 
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
 
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

Featured Post

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now