有一段stringgrid中增加checkbox控件的代码,你可以参考一下:
var
i: integer;
chk: TCheckBox;
rt: TRect;
begin
for i := 1 to stringgride.RowCount - 1do
begin
chk := TCheckBox.Create(Self);
chk.Caption := '定制';
chk.Parent := stringgride;
chk.Tag := i;
rt := stringgride.CellRect(ColNo_IsCustom,i);
with chkdo
begin
Left := stringgride.Left + rt.Left + 5;
Top := stringgride.Top + rt.Top + 4;
Width := rt.Right - rt.Left - 14;
Height := stringgride.DefaultRowHeight - 4;
Font.Size := 11;
end;
chk.OnClick := chkIsCustomClick;
chk.OnKeyPress := chkIsCustomKeyPress;
end;
end;