// Must declare a a global variable for this form
private
FOriginalOptions : TDBGridOptions;
//************************************************
// FORM CELL CLICK
procedure
TFrmFile.DBGridCellClick(Column: TColumn);
begin
if Self.DBGrid.SelectedField.DataType =
ftBoolean then
SaveBoolean();
end;
//************************************************
// FORM SAVE BOOLEAN
procedure
TFrmFile.SaveBoolean;
begin
Self.DBGrid.SelectedField.Dataset.Edit;
Self.DBGrid.SelectedField.AsBoolean := not
Self.DBGrid.SelectedField.AsBoolean;
Self.DBGrid.SelectedField.Dataset.Post;
end;
//************************************************
// (FORM) DRAW CHECKBOX IF FIELD TYPE IS BOOLEAN
procedure
TFrmFile.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State:
TGridDrawState);
Const
CtrlState : array[Boolean] of Integer =
(DFCS_BUTTONCHECK,
DFCS_BUTTONCHECK or DFCS_CHECKED);
var
CheckBoxRectangle : TRect;
begin
if Column.Field.DataType = ftBoolean then
begin
Self.DBGrid.Canvas.FillRect(Rect);
CheckBoxRectangle.Left := Rect.Left + 2;
CheckBoxRectangle.Right := Rect.Right - 2;
CheckBoxRectangle.Top := Rect.Top + 2;
CheckBoxRectangle.Bottom := Rect.Bottom - 2;
DrawFrameControl(Self.DBGrid.Canvas.Handle,
CheckBoxRectangle,
DFC_BUTTON,
CtrlState[Column.Field.AsBoolean]);
end;
end;
//************************************************
// (FORM) DBGRID COL ENTER
procedure
TFrmFile.DBGridColEnter(Sender: TObject);
begin
if Self.DBGrid.SelectedField.DataType =
ftBoolean then
begin
Self.FOriginalOptions :=
Self.DBGrid.Options;
Self.DBGrid.Options := Self.DBGrid.Options -
[dgEditing];
end;
end;
//************************************************
// (FORM) DBGRID COL EXIT
procedure
TFrmFile.DBGridColExit(Sender: TObject);
begin
if Self.DBGrid.SelectedField.DataType =
ftBoolean then
Self.DBGrid.Options :=
Self.FOriginalOptions;
end;