Solved

Formatting cels in a TDBgrid

Posted on 1997-11-28
5
197 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 103
Magic Software info 18 130
control image tags in a string ? 12 129
Delphi: making a BW image transparent 10 37
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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