Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Formatting cels in a TDBgrid

Posted on 1997-11-28
5
Medium Priority
?
208 Views
Last Modified: 2010-04-04
Field in database floating point with value 0.85
To display as 85%
0
Comment
Question by:mvsatis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 4

Expert Comment

by:itamar
ID: 1352317
AFAIK, you must include a calculated field in your TTable or TQuery object that will be calculated as:

NewField := OriginalField * 100;

Change the display property of this field to '##0%'
Include the calculated field in the DBGrid, instead of the original field column.

If you need some code, please increase the points.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1352318
Itamar, why making a new field (calculated)?

AFAIK, this is another solution, it's up to you which one you like the most. This one doesn't need a calculated field :

Select Table :
  -> Right-click : -> you come in the field editor
  -> Right-click : -> Add fields (choose which fields you want,
normally All, because the one you don't choose won't be visible in the DBGrid)
  -> Click on the field you want to change the display.
  -> Go to object inspector.
     And fill in the mask in the displayformat property
     choose for example the one from itamar ##0%
                      or #.#%

--->>>> This field of this Ttable will ALWAYS be showed like
 you defined in the displayformat property!
 (e.g. TDBGrid, TDBCaption, ...)

Have fun,
c.u. ZifNab;
 
                                   
0
 
LVL 4

Expert Comment

by:itamar
ID: 1352319
Well Zif, i believe this way the value 0.85 (in the given example) will be showed as 0.9% or 1% NOT 85%, isn't it ?
That's why i proposed the calculated field.

Hey mvsatis, give us some feedback...
0
 
LVL 4

Accepted Solution

by:
itamar earned 150 total points
ID: 1352320
Here goes a step-by-step answer;

1. Double-click a Dataset (TTable or TQuery) component to bring up its Field Editor.

2. Right-click the list of fields and select New field from the menu.

3. In the New Field dialog, type the name you want to use for your new calculated field, select its data Type (float), and click the Calculated radio button in the Field type radio button group;

4. Click OK to finish your definition.

When you return to the Fields Editor, you should see the new field's properties listed in Delphi's Object inspector.

5. Now that the field is defined, set up an OnCalcFields event for your Dataset that assigns a value to the new field. An example for this case:

begin
   Table1NewField.Value := Table1OriginalField.Value * 100;

6. In the Object Inspector change the Displaformat property for Table1NewField to ##0%

Please, give some feedback.
0
 

Author Comment

by:mvsatis
ID: 1352321
Thanks itamar,
My first approach was the same and it did not work due to a failure in the dispalyformat property.
After reading your answer everything is OK.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 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