2
Good morning, everyone...
I have a table in an Sqlite database with an "integer" type field to store "Boolean" values. This field is linked, on the registration screen, to a Dbcheckbox. So, to be able to mark and unmark the Dbcheckbox, I needed to write the Ongettext and Onsettext events from the field.
Now I need to show "Yes" and "No" values based on this field in a Dbgrid. I wrote the code below in the Ondrawcolumncell event:
procedure TfrmPesquisar.dbgPesquisarDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.Field = dsPesquisar.DataSet.FieldByName('claAtiva') then
begin
dbgPesquisar.Canvas.FillRect(Rect);
if Column.Field.AsString = '0' then
dbgPesquisar.Canvas.TextOut(Rect.Left+10,Rect.Top+3,'Não')
else
dbgPesquisar.Canvas.TextOut(Rect.Left+10,Rect.Top+3,'Sim');
end;
end;
However, only the first line is showing, erroneously, the value to be replaced (No) and the real value (0 - zero), as shown below:
Has anyone gone through something similar or knows the solution ?
Thank you so much for your help.
I had not noticed... The two data are presented on the selected line. Then if I select the second or third line the data "Yes" and "1".
– BJA
And if you create a Calculated Field in the Dataset that feeds this Grid?
– Junior Moreira
Try to add at the end of the code, after the
IF
:dbgPesquisar.DefaultDrawDataCell(Rect,Column.Field,State);
– Andrey
Andrey. When this line is added, the display of the information is reversed. In all three lines appear the real values (0, 1, 1) and in the selected row also appears "Yes" or "No" depending on the value (whether it is 0 or 1).
– BJA
@Junior Moreira. I am not using Fields Editor because it is a generic screen and the data is brought through an SQL statement in a Tfdquery. So I guess you can’t do it that way.
– BJA
@Andrey. When this line is added, the display of the information is reversed. In all three lines appear the real values (0, 1, 1) and in the selected row also appears "Yes" or "No" depending on the value (whether it is 0 or 1).
– BJA