Board index » delphi » DBCheckBox Questions?

DBCheckBox Questions?

Hi all.

I'm using Delphi 5 Enterprise and MS Access 97.

Using a DBCheckBox I would like that:
1) if the value is any number, then DBCheckBox would be Checked
2) if the value is null, then DBCheckBox would be Not Checked.

Another question - DBCheckBox usually has 3 states: Checked, Not
Checked, and "Checked grayed".
Is it possible to represent only 2 values, ie, Checked and Not
Checked. ( If the DBCheckBox is to be "Checked Grayed" then it
would be Not Checked ).

Thanks a lot in advance.

Best regards,
       Joaquim.

 

Re:DBCheckBox Questions?


No to both questions.

--
Bill

Re:DBCheckBox Questions?


Quote
"Joaquim Macedo" <joaquimmac...@yahoo.com> wrote in message

news:3b5701d9$1_1@dnews...

Quote

> Using a DBCheckBox I would like that:
> 1) if the value is any number, then DBCheckBox would be Checked
> 2) if the value is null, then DBCheckBox would be Not Checked.

> Another question - DBCheckBox usually has 3 states: Checked, Not
> Checked, and "Checked grayed".
> Is it possible to represent only 2 values, ie, Checked and Not
> Checked. ( If the DBCheckBox is to be "Checked Grayed" then it
> would be Not Checked ).

Use the OnGetText method of the field you have the DBCheckBox connected to.
If the field is null, set the text to 'True', else 'False' (or anything else
you want as long as you match it in the DBCheckbox.ValueChecked /
ValueUnchecked properties).

A sample using DBDEMOS Clients.dbf Risk_Level field:

procedure TForm1.Table1RISK_LEVELGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
  if Sender.AsString = 'HIGH' then Text := 'True'
  else Text := 'False';
end;

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Re:DBCheckBox Questions?


Thanks Bill and Wayne, for answering.

Wayne,
I'm trying this, on OnGetText field event:
---------------------------------------------------------------
  if Sender.IsNull then
     Text := 'N'
  else
      Text := 'Y';
---------------------------------------------------------------

The DBCheckBox properties are:
    ValueChecked = 'Y'
    ValueUnchecked = 'N'

When it returns 'Y', the DBCheckBox is Checked, else the
DBCheckBox is "grayed".
I'm doing anything wrong?

I don't know if this is important - the data type field is TSmallInt.

Best regards,
     Joaquim.

"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote:

Quote
>"Joaquim Macedo" <joaquimmac...@yahoo.com> wrote in message
>news:3b5701d9$1_1@dnews...

>> Using a DBCheckBox I would like that:
>> 1) if the value is any number, then DBCheckBox would be Checked
>> 2) if the value is null, then DBCheckBox would be Not Checked.

>> Another question - DBCheckBox usually has 3 states: Checked, Not
>> Checked, and "Checked grayed".
>> Is it possible to represent only 2 values, ie, Checked and Not
>> Checked. ( If the DBCheckBox is to be "Checked Grayed" then it
>> would be Not Checked ).

>Use the OnGetText method of the field you have the DBCheckBox connected to.
>If the field is null, set the text to 'True', else 'False' (or anything else
>you want as long as you match it in the DBCheckbox.ValueChecked /
>ValueUnchecked properties).

>A sample using DBDEMOS Clients.dbf Risk_Level field:

>procedure TForm1.Table1RISK_LEVELGetText(Sender: TField; var Text: String;
>  DisplayText: Boolean);
>begin
>  if Sender.AsString = 'HIGH' then Text := 'True'
>  else Text := 'False';
>end;

>--
>Wayne Niddery (Logic Fundamentals, Inc.)
>RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
>"Some see private enterprise as a predatory target to be shot, others as a
>cow to be milked, but few are those who see it as a sturdy horse pulling the
>wagon." - Winston Churchill

Re:DBCheckBox Questions?


Quote
"Joaquim Macedo" <joaquimmac...@yahoo.com> wrote in message

news:3b585b54$1_2@dnews...

Quote

> I'm trying this, on OnGetText field event:
> ---------------------------------------------------------------
>   if Sender.IsNull then
>      Text := 'N'
>   else
>       Text := 'Y';
> ---------------------------------------------------------------

> The DBCheckBox properties are:
>     ValueChecked = 'Y'
>     ValueUnchecked = 'N'

> When it returns 'Y', the DBCheckBox is Checked, else the
> DBCheckBox is "grayed".
> I'm doing anything wrong?

Looks like it should work to me. I tested my example to be sure it worked
before I posted it. Is there any other code in the OnGetText even that could
be bypassing the code you post above? The field type should be irrelevant as
long as you are testing it appropriately. Try using 'T' and 'F' ijnstead of
'Y' and 'N'.

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Re:DBCheckBox Questions?


Wayne,

Thanks again for your reply.

It seems to me that if the field's value is Null, then the event
OnGetText does not fire.
This is the reason I'm not getting what I want. The DBCheckBox
gets Checked, because the field's value is not null.

Best regards,
     Joaquim.

"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote:

Quote
>"Joaquim Macedo" <joaquimmac...@yahoo.com> wrote in message
>news:3b585b54$1_2@dnews...

>> I'm trying this, on OnGetText field event:
>> ---------------------------------------------------------------
>>   if Sender.IsNull then
>>      Text := 'N'
>>   else
>>       Text := 'Y';
>> ---------------------------------------------------------------

>> The DBCheckBox properties are:
>>     ValueChecked = 'Y'
>>     ValueUnchecked = 'N'

>> When it returns 'Y', the DBCheckBox is Checked, else the
>> DBCheckBox is "grayed".
>> I'm doing anything wrong?

>Looks like it should work to me. I tested my example to be sure it worked
>before I posted it. Is there any other code in the OnGetText even that could
>be bypassing the code you post above? The field type should be irrelevant as
>long as you are testing it appropriately. Try using 'T' and 'F' ijnstead of
>'Y' and 'N'.

>--
>Wayne Niddery (Logic Fundamentals, Inc.)
>RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
>"Some see private enterprise as a predatory target to be shot, others as a
>cow to be milked, but few are those who see it as a sturdy horse pulling the
>wagon." - Winston Churchill

Other Threads