DBAdvGrid and combostrings

Hello,

I am trying to replace the True/False displayed by default in a DBAdvGrid linked to a boolean field with a Yes/No.


I have implemented the metod DBAdvGridCategoryListGetEditorProp in the following way:
    case ACol of
        5: begin
            DBAdvGridCategoryList.ClearComboString;
            DBAdvGridLinkCategoryActions.AddComboString('Yes');
            DBAdvGridLinkCategoryActions.AddComboString('No');
        end;

and the method DBAdvGridCategoryListGetEditorType in the following way:
    case ACol of
        5:AEditor:=edComboList;
    end;



The yeses/nos are shown correctly but when I try to change the value I have an error message ('no', is not a valid boolean value for a field xxxxx)

I tried to implement the method procedure TFormCustomerCategoryManager:
    case ACol of
        5:begin
            if Value='Yes' then
                DataModule1.PgTable.FieldByName('xxx').AsBoolean:=true
            else
                DataModule1.PgTable.FieldByName('xxxxxxx').AsBoolean:=false;

but it doesn't work.

I have also looked into the samples but didn't find anything.


How can I fix it ?


Many thanks


Alberto

Sorry, the last method I implemented is DBAdvGridLinkCategoryActionsCellValidate
 case ACol of
        5:begin
            if Value='Yes' then
                DataModule1.PgTable.FieldByName('xxx').AsBoolean:=true
            else
                DataModule1.PgTable.FieldByName('xxxxxxx').AsBoolean:=false;

The recommended way is to use a checkbox for boolean fields (set grid.ShowBooleanFields = true for this)

If you don't want this, you could consider mapping Yes/No into the boolean string values:

procedure TForm4.AdvStringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer;
  var Value: string);
begin
   if ACol = 5 then
   begin
        if Value = 'Yes' then Value := 'true' else value := 'false';
   end;
end;



I tried this one and I can select the option yes/no correctly but when I try to move to another cell I have the EDatabaseError "no is not a valid boolean value for field xxxxx". It seems GetEditText designate Value to the db field.

I also tried to implement GetDisplText

procedure TForm4.AdvStringGrid1GetDisplText(Sender: TObject; ACol, ARow: Integer;
  var Value: string);
begin
   if ACol = 5 then
   begin
        if Value = 'true' then Value := 'yes' else value := 'no';
   end;
end;
but I have the same error message

How can I solve this ?

Many thanks


Alberto

What database do you connect to?
Normally, you would return the string values that you would normally use to update the DB field with

DBField.AsString := 'TRUE'

What is your DB using as string values for boolean TRUE/FALSE values? Try to use these values.

Hello Bruno,

My database is PostgreSQL. I did some tests. I ran the query UPDATE table SET fieldname='No'; directly from the console and everything works. That means PostgreSQL accept No/Yes as valid data for boolean fields.

Then I connected a fresh datasource+dataset to a normal DBGrid, typed "Yes" and I have the same error message I mention in my previous posts. That means the problem seems to reside in the Data Access Component I use to connect my application to PostgreSQL. I will address the issue to the other company.

Thank you very much for your help

Alberto