发一个dbcheckbox,visible属性设置为false;dbgrid的defaultdrawing属性设置为True procedure TForm1.Dbgrid1drawcolumncell(sender:Tobject;Const Rect:Trect;.....); begin if (gdfocused in state)and(column.field=Table1senior) then begin dbcheckbox1.setbount(rect.left+dbgrid1.left+1, Rect.top+dbgrid1.top+1, rect.right-rect.left, rect.bottom-rect.top); end; end;procedure TForm1.dbgird1colenter(...); begin if dbgrid1.columns[dbgrid1.selectedindex].field=table1senior then dbcheckbox1.visible:=true else dbcheckbox1.visible:=false; end;procedure TForm1.dbgrid1keypress(..); begin if dbcheckbox1.visible and (ord(key)>31) then begin key:=#0; table1.edit1; dbcheckbox1.checked:=not dbcheckbox1.checked; dbcheckbox1.field.asbooolean:=dbcheckbox1.checked; end; end;
procedure TForm1.Dbgrid1drawcolumncell(sender:Tobject;Const Rect:Trect;.....);
begin
if (gdfocused in state)and(column.field=Table1senior) then
begin
dbcheckbox1.setbount(rect.left+dbgrid1.left+1,
Rect.top+dbgrid1.top+1,
rect.right-rect.left,
rect.bottom-rect.top);
end;
end;procedure TForm1.dbgird1colenter(...);
begin
if dbgrid1.columns[dbgrid1.selectedindex].field=table1senior then
dbcheckbox1.visible:=true
else
dbcheckbox1.visible:=false;
end;procedure TForm1.dbgrid1keypress(..);
begin
if dbcheckbox1.visible and (ord(key)>31) then
begin
key:=#0;
table1.edit1;
dbcheckbox1.checked:=not dbcheckbox1.checked;
dbcheckbox1.field.asbooolean:=dbcheckbox1.checked;
end;
end;
属性!填写它!
在运行程序后,单机这个列,就有类似checkbox的下拉列表!