Solved

Formatting cels in a TDBgrid

Posted on 1997-11-28
5
195 Views
Last Modified: 2010-04-04
Field in database floating point with value 0.85
To display as 85%
0
Comment
Question by:mvsatis
  • 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

19 Experts available now in Live!

Get 1:1 Help Now