Recent

Author Topic: Select the ID from tdbGrid  (Read 6846 times)

christensen

  • Full Member
  • ***
  • Posts: 127
Select the ID from tdbGrid
« on: April 24, 2010, 09:45:39 pm »
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: [Select]
grdSearch.TDBgrid.DisplayText

Thanks in advanced
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

cpalx

  • Hero Member
  • *****
  • Posts: 754
Re: Select the ID from tdbGrid
« Reply #1 on: April 24, 2010, 10:24:13 pm »
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

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Select the ID from tdbGrid
« Reply #2 on: April 25, 2010, 10:20:49 am »
I've try like this but doesn't work. the same result i get

Code: [Select]
frmSettings.dsSearchGrd.DataSet.FieldByName('ID').AsString

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?
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

cpalx

  • Hero Member
  • *****
  • Posts: 754
Re: Select the ID from tdbGrid
« Reply #3 on: April 25, 2010, 01:53:10 pm »
i dont know what componets dou you use, but could be:

Zquery.fieldbyname('ID').asString

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

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Select the ID from tdbGrid
« Reply #4 on: April 25, 2010, 05:36:19 pm »
Thanks!

It was my mistake, I have a few Query components on the form and one of them I had connected wrong.
 
Now is working!
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

 

TinyPortal © 2005-2018