首先要在DBGrid所对应的DataSet中加一个计算字段,比方说为DEL,初始值为0 然后在OnDrawDataCell事件中写如下代码 var R: TRect; begin if Field.FieldName = 'DEL' then with DBGrid1.Canvas do begin FillRect(Rect); R := Rect; InflateRect(R, -2, -2); if Field.AsString = '1' then DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_CHECKED) else DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK); end; end;在OnCellClick事件中写如下代码 if Column.FieldName = 'DEL' then with DBGrid1.DataSource.DataSet do begin Edit; if FieldByName('DEL').AsString = '1' then FieldByName('DEL').AsString := '0' else FieldByName('DEL').AsString := '1'; Post; end; 要删除时只要判断DEL字段是否为1便可。
然后在OnDrawDataCell事件中写如下代码
var
R: TRect;
begin
if Field.FieldName = 'DEL' then
with DBGrid1.Canvas do
begin
FillRect(Rect);
R := Rect;
InflateRect(R, -2, -2);
if Field.AsString = '1' then
DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_CHECKED)
else
DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK);
end;
end;在OnCellClick事件中写如下代码
if Column.FieldName = 'DEL' then
with DBGrid1.DataSource.DataSet do
begin
Edit;
if FieldByName('DEL').AsString = '1' then
FieldByName('DEL').AsString := '0'
else
FieldByName('DEL').AsString := '1';
Post;
end;
要删除时只要判断DEL字段是否为1便可。