Solved

Formatting cels in a TDBgrid

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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