procedure TForm13.DBGrid1CellClick(Column: TColumn);
begin
  if (Column.Field.FieldName = 'aboolean') then
  begin
    DBGrid1.SelectedField.DataSet.Edit;
    if DBGrid1.SelectedField.AsInteger = 0 then
      DBGrid1.SelectedField.AsInteger := 1
    else if DBGrid1.SelectedField.AsInteger = 1 then
      DBGrid1.SelectedField.AsInteger := 0;
    DBGrid1.SelectedField.DataSet.Post;
  end;

end;
//=========================================================================
 procedure TForm13.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const
  CtrlState: array [Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or   DFCS_CHECKED); // CheckBox1 列 要用到的
begin 
 if (Column.Field.FieldName = 'aboolean') then
    with CheckBox1 do
    begin
      DBGrid1.Canvas.FillRect(Rect);
      if Column.Field.AsInteger = 0 then
        drawframecontrol(DBGrid1.Canvas.Handle, Rect, dfc_button,      CtrlState[False])
      else
        drawframecontrol(DBGrid1.Canvas.Handle, Rect, dfc_button,      CtrlState[True]);
    end;

end;
//==============================================================================
procedure TForm13.FormCreate(Sender: TObject);
   DBGrid1.Options:= DBGrid1.Options-[ dgEditing];  //CheckBox1 不要 双击后,出现 0的Edit显示
end;
//==============================================================================
procedure TForm13.DBGrid1TitleClick(Column: TColumn);  //CheckBox1专用
var
  i: Integer;
begin
  if (Column.Field.FieldName = 'aboolean') then
  begin
    FDQuery1.First; // 游标回滚
    DBGrid1.SelectedRows.CurrentRowSelected := True; // 第一行被选中

    if trim(Column.Title.Caption) = '全选' then
    begin
      for i := 0 to DBGrid1.DataSource.DataSet.RecordCount - 1 do
      begin
        DBGrid1.Fields[3].DataSet.Edit;          //3为  ChechBox1所在的列序号
        DBGrid1.Fields[3].AsInteger := 1;
        DBGrid1.Fields[3].DataSet.Post;
        DBGrid1.DataSource.DataSet.next;
      end;
      Column.Title.Caption := '全消';
    end
    else
    begin
      for i := 0 to DBGrid1.DataSource.DataSet.RecordCount - 1 do
      begin
        DBGrid1.Fields[3].DataSet.Edit;
        DBGrid1.Fields[3].AsInteger := 0;
        DBGrid1.Fields[3].DataSet.Post;
        DBGrid1.DataSource.DataSet.next;
      end;
      Column.Title.Caption := '全选';
    end;
    FDQuery1.First; // 游标回滚
    DBGrid1.SelectedRows.CurrentRowSelected := True; // 选中第一行
  end;
end;