[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

Display alternative value in DBGrid...?

Hi,

When I display the content of a database table in a DBGrid, all the boolean fields will display "true" or "false".

My question: how can I change this in order to see "yes" and "no" instead of "true" and "false" in the DBGrid component? Any other alternative value must be possible in order to support multiple languages.

Thank you in advance.

RoosieDB
0
roosiedb
Asked:
roosiedb
  • 3
  • 3
  • 2
  • +1
1 Solution
 
MotazCommented:
You can use calculated field.

- Double click at the dataset that your dbGrid connected to.
- At fields editor right click and select Add all fields
- Right click again and select New Field
- At name box write YesNoField. At Type combo box select string and specify 3 in it's size field. At field type select Calculated.
- Display events tab of your datasource component, double click at OnCalcFields event and write:

  if DataSet.FieldByName('BooleanField').AsBoolean then
  DataSet.FieldByName('yesNoField').AsString:= 'Yes'
  else
  DataSet.FieldByName('yesNoField').AsString:= 'No'


I supposed that your boolean field called 'BooleanField'

Shufta kaif
Motaz
0
 
kretzschmarCommented:
you could also use the ongettext/onsettext-events of this field
0
 
roosiedbAuthor Commented:
Hi,

I will try this tonight... thank you in advance (for your quick reply)...

gr.,
RoosieDB
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
marcoszorrillaCommented:
You can double click the Ttable and add all the fields, select your boolean field and in DisplayValues property.
You write for example Sí;No
or
Yes;Not
Oui;Non

As this property can be changed in runtime.

Best Regards
Marcos
0
 
kretzschmarCommented:
yep, marcos,
i was not sure,
because no delphi on hand
0
 
marcoszorrillaCommented:
Danke Kretzschmar.
I forgot
Ja;Nein.

Best Regards
Marcos.
0
 
MotazCommented:
There is a more easy solution without modifying any property :

after opening your table write:

  Table1.Open;
  TBooleanField(Table1.FieldByName('Bool')).DisplayValues:= 'Yes;No';


Motaz
0
 
roosiedbAuthor Commented:
For your information, I will use "JA" and "NEE" (as in Dutch)... Later on I will add some more languages in here...

gr.,
RoosieDB

P.S. Last night I did not have the chance to try this solution, I will retry tonight...
0
 
marcoszorrillaCommented:
This is the idea. You can create a Global Variable for language that the user can select, and then write a function that returns the correct string.

Here you have an example and the idea you don't have more than to adapt it to your necessities.

Best Regards
Marcos.


procedure TForm1.Button1Click(Sender: TObject);
Var
cBoolShow:String;
nLanguage:Integer;
begin
nLanguage:=0;
Case nLanguage of
0:cBoolShow:='Ja;Nee';
1:cBoolShow:='yes;Not';
2:cBoolShow:='Oui;Non';
3:cBoolShow:='Ja;Nein';
4:cBoolShow:='Sí;no';
end;
Table1MyField.DisplayValues:=cBoolShow;
end;
0
 
roosiedbAuthor Commented:
Working perfect !

Thanx.

RoosieDB
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now