Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting 1 row of a TDBGrid

Status
Not open for further replies.

tomstra

Programmer
Oct 30, 2000
6
US
I am presenting a TDBGrid to the user. I want him to select one and only one record. If he does not select a record, I want to put out an error message saying 'select a record'. The DataSource for the TDBGrid is a TQuery.
If I use the TDBGrid with the default values, if the user does not select a record and hits the 'continue' button, the query thinks the first record was selected. If I interrogate SelectedRows.Count, as long as dgMultiSelect is false, count = 0 even if the user has selected a row. As soon as I change dgMultiSelect to true (and dgRowSelect to true), SelectedRows.Count contains the number of rows selected, but I don't want to give the user the ability to select multiple rows.
Any ideas on how I can only allow the user to select one row and yet be able to detect if the user has in fact selected a row?
(We're running Delphi 4 Professional.)
 
You'd have to play around with the code, but...
How about adding a second grid underneath the main Tdbgrid.
Add a button between the two that, when clicked, inserts the selected row in the top grid into the bottom grid. then use the bottom grid as the record you pass to your next procedure.
 
Dear Nebuchednezzar,
Thank you for your creative reply. I guess I am hoping that perhaps there is some property of TDBGrid that I have overlooked that will cause it to act the way I want it to act so that I won't have to write any fancy code. I guess I am a bit stunned that the TDBGrid tells me the first row is selected when no rows are selected (when I am in single-row select mode).
But, thanks for your reply!
-tomstra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top