Hola Miguel.
No es necesario que el campo sea booleano, para eso están las propiedades
ValueChecked y
ValueUnChecked del
TDBCheckBox:
Código Delphi
[-]
procedure TForm1.FormCreate(Sender: TObject);
begin
with DBCheckBox1 do
begin
Caption:= '';
ValueChecked:= 'S';
ValueUnchecked:= 'N';
Visible:= False;
end;
IBDataset1.Open;
end;
El resto del código sólo necesita unos cambios menores.
Código Delphi
[-]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
const
IsChecked: array[Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK+DFCS_CHECKED);
var
DrawState: Integer;
DrawRect: TRect;
begin
if gdSelected in State then
begin
if Column.FieldName = DBCheckBox1.DataField then
begin
DBGrid1.Canvas.Brush.Style:= bsSolid;
DBGrid1.Canvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect. Bottom);
DBCheckBox1.Left := Rect.Left + DBGrid1.Left + 2;
DBCheckBox1.Top := Rect.Top + DBGrid1.top + 2;
DBCheckBox1.Width := (Rect.Right - Rect.Left + 4) div 2;
DBCheckBox1.Height := Rect.Bottom - Rect.Top;
DBCheckBox1.Visible := True;
DBCheckBox1.SetFocus;
end
end
else if Column.FieldName = DBCheckBox1.DataField then
begin
DrawRect := Rect;
InflateRect(DrawRect,-1,-1);
DrawState := IsChecked[Column.Field.AsString='S'];
DBGrid1.Canvas.FillRect(Rect);
DrawFrameControl(DBGrid1.Canvas.Handle,DrawRect,DFC_BUTTON,DrawState);
end;
end;
procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
with DBCheckBox1 do
Visible:= not (DBGrid1.SelectedField.FieldName = DataField)
end;
procedure TForm1.DBCheckBox1Exit(Sender: TObject);
begin
IBDataSet1.Edit;
IBDataSet1.Post;
end;
...
Saludos