?
Solved

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

Posted on 2003-03-11
4
Medium Priority
?
176 Views
Last Modified: 2010-04-04
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
Comment
Question by:Apie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Stefaan
ID: 8110717
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
 
LVL 3

Accepted Solution

by:
Stefaan earned 50 total points
ID: 8110743
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
 
LVL 4

Expert Comment

by:cjm30305
ID: 8113843
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
 

Expert Comment

by:CleanupPing
ID: 9316845
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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