Recent

Author Topic: How to set FieldName in DBGrid  (Read 2469 times)

erictan

  • Jr. Member
  • **
  • Posts: 54
How to set FieldName in DBGrid
« on: June 07, 2020, 05:53:00 am »
I have added a DBGrid, DBConnection, DataSource, SQLQuery and SQLTransaction on a Form and is able to run and extract all data from a table.

But I only want to specify selected columns and have called up the "Editing DBGrid Column" option of the DBGrid and added 3 columns. When I tried to specify the FieldName of each column, I get the message "Unable to retrieve definition from dataset"

Please advise how I can fixed this issue as I tried to google for a solution without success.


eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: How to set FieldName in DBGrid
« Reply #1 on: June 07, 2020, 09:25:14 am »
When I tried to specify the FieldName of each column, I get the message "Unable to retrieve definition from dataset"
There are two ways to solve this problem.
1) Use static fields on the dataset instead of dynamic. You can do that by right clicking on the dataset and selecting edit fields. in the dialog that pops right click on the list and select add fields. The rest should be self evident.

2) connect the dataset to the database and make sure that its active and the data are properly retrieved, after that you can add link the fields to the dbgrid with out problems.


JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: How to set FieldName in DBGrid
« Reply #2 on: June 07, 2020, 11:10:32 am »
The third way of setting the fieldnames is by clicking the message away and then enter the fieldname in manually in the Object Inspector. If you make no typing errors in the name that will also show you the fields content in the dbgrid in runtime.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

erictan

  • Jr. Member
  • **
  • Posts: 54
Re: How to set FieldName in DBGrid
« Reply #3 on: June 07, 2020, 11:28:52 am »
Thank you eljo and JanRoza for your reply.
I manage to follow eljo's 1st suggestion and can now set any fields I need from the table.
How do I change the field Title as I could not find any place in the Object Inspector to change it.

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: How to set FieldName in DBGrid
« Reply #4 on: June 07, 2020, 11:38:18 am »
Thank you eljo and JanRoza for your reply.
I manage to follow eljo's 1st suggestion and can now set any fields I need from the table.
How do I change the field Title as I could not find any place in the Object Inspector to change it.
the Tfield have a property named DisplayLabel. What ever is set there will be set as the columns title. also the dbcolumn has a title.caption property which you can set.

erictan

  • Jr. Member
  • **
  • Posts: 54
Re: How to set FieldName in DBGrid
« Reply #5 on: June 07, 2020, 11:44:47 am »
Thank you both again, greatly appreciate your help.

 

TinyPortal © 2005-2018