Solved

ADO Display label in DB grid

Posted on 2004-04-12
5
255 Views
Last Modified: 2010-04-05
HI I would like to know how do you change the display label of a field in the grid if your TADOQuery SQL are both declared in the codes instead of using components.
looking at the example below, the genre will display as GENRE, product_type will be display as PRODUCT_TYPE in my grid. How do you change it? do i have to declare the stringfields or tfields? I don't know how to do it. Please help.THANKS!

procedure  TFrameProductBook.BitBtnCategoryLookUPClick(Sender: TObject);
var SQL :string;

begin
 SQL := 'select genre, category_id from category, product_type';
 SQL := SQL + ' where product_type = ''B''';
  SQL := SQL + ' order by :order';
  with FormCategoryLU do
  begin
  QryLU.SQL.text := SQL;

  QryLU.Open;
.
,
,
0
Comment
Question by:AgeOfWars
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:mokule
Comment Utility
   for i := 0 to DBGrid1.Columns.Count - 1 do
      begin
      if DBGrid1.Columns[i].FieldName = 'genre' then
        DBGrid1.Columns[i].Title.Caption := 'Caption genre;
      .....
      end;
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
You can also rewrite

 SQL := 'select genre as caption, category_id from category, product_type';

Choose what is more convenient in a given circumstances.
0
 

Author Comment

by:AgeOfWars
Comment Utility
Hi mkule,
Thanks for you reply. the first one didn't work for me :(
I know that you can manupulate the sql statement, but i wanna find out how to play with the field settings. the Tstringfileds and the Tfields in the columns of the Query because I would wanna make some of them invisible.

do you know any other way? Thanks

Ian
0
 

Author Comment

by:AgeOfWars
Comment Utility
Hi Mokule,

I have this error.

SQL := 'select genre, category_id from category, product_type';
 SQL := SQL + ' where product_type = ''B''';
  SQL := SQL + ' order by :order';

I can write 'select genre as CAPTION but it would appear as CAPS.
If I tried 'select genre as ''Genre'' from category' it will return error.

Please help.
Thank you
ian

0
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
Comment Utility
It should work.
One apostrophe was missed
What do you mean be don't work.

for i := 0 to DBGrid1.Columns.Count - 1 do
      begin
->>  if DBGrid1.Columns[i].FieldName = 'genre' then
          DBGrid1.Columns[i].Title.Caption := 'Caption genre';
      end;

stop program on this instruction in the loop and look what are Your Filed names
If they are CAPS rewrite as

  if DBGrid1.Columns[i].FieldName = 'GENRE' then
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now