Forum > General

Select the ID from tdbGrid


Hi guys!

I'm new in Lazarus and in Pascal.

I have problem selecting the first column from tbdGrid.
When the program start fill up(database all fields: id, Name, Surname, Address, Phone) the TDBgrid and at OnCellClick event i select from TDBgrid just the ID, but depend where i'm clicking if i click o ID i get the ID and if i click on Name or Surname i get those values and not the ID

How can I select the field but should return the ID (first column from tdbGrid).

--- Code: ---grdSearch.TDBgrid.DisplayText
--- End code ---

Thanks in advanced

Why dont you use you dataset, when you select in any cell of your dbgrid, the dataset move with it, So you can get your ID something like yourdataset.fielbyname('fielID').asstring

I've try like this but doesn't work. the same result i get

--- Code: ---frmSettings.dsSearchGrd.DataSet.FieldByName('ID').AsString
--- End code ---

Only than work if in the query is selected only the ID field, but in my case cannot select only the ID field I need others as well.
Any other possibility?

i dont know what componets dou you use, but could be:


ID: The name of the field make in your query. It works


It was my mistake, I have a few Query components on the form and one of them I had connected wrong.
Now is working!


[0] Message Index

Go to full version