DBGrid Boolean Field - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

DBGrid Boolean Field

_yilmaz_yilmaz Posts: 150Member
Hi;

If there is a boolean field, a DBGrid displays the data as "True"
or "False". Is there a way to customize these?

That is, for example, I want to display "True" as "X", and False as
"Y".

Thanx.

Comments

  • pak77pak77 Posts: 28Member
    : Hi;
    :
    : If there is a boolean field, a DBGrid displays the data as "True"
    : or "False". Is there a way to customize these?
    :
    : That is, for example, I want to display "True" as "X", and False as
    : "Y".
    :
    : Thanx.
    :
    : Im pretty sure that this isn't possible as boolean fields will only
    : accept either "True/False", "Yes/No" or "On/Off".
    :
    : The way I would do this would be to create a seperate field in your
    : database and when the user inputs "True/False" post the
    : corresponding value into this field. Then display this field in your
    : grid.

  • zibadianzibadian Posts: 6,349Member
    : Hi;
    :
    : If there is a boolean field, a DBGrid displays the data as "True"
    : or "False". Is there a way to customize these?
    :
    : That is, for example, I want to display "True" as "X", and False as
    : "Y".
    :
    : Thanx.
    :
    You can use a calculated field to be shown in the datagrid. Then in the OnCalculate() you get/set the actual boolean field value into the database.
  • AtulParmarAtulParmar Posts: 14Member
    : Hi;
    :
    : If there is a boolean field, a DBGrid displays the data as "True"
    : or "False". Is there a way to customize these?
    :
    : That is, for example, I want to display "True" as "X", and False as
    : "Y".
    :
    : Thanx.
    :
    Hello,

    You can do it by the boolean field's gettext and settext event
    here is how

    procedure TForm1.Table1MyFieldGetText(Sender: TField; var Text: String;
    DisplayText: Boolean);
    begin
    if Sender.AsBoolean then
    Text := 'X'
    else
    Text := 'Y';
    end;

    procedure TForm1.Table1MyFieldSetText(Sender: TField;
    const Text: String);
    begin
    Sender.AsBoolean := Text = 'X';
    end;


Sign In or Register to comment.