Solved

Formatting cels in a TDBgrid

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

617 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