with TCheckBox(StringGrid1.Objects[1, i]) do
begin
OnKeyUp := CheckBoxKeyUp;
OnMouseUp := CheckBoxMouseUp;
Parent := StringGrid1;
BoundsRect := StringGrid1.CellRect(1, i);
Width := StringGrid1.ColWidths[1];
Height := StringGrid1.RowHeights[1];
Checked := True;
end;
end;
end;
procedure Form1.CheckBoxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
with TCheckBox(Sender) do
Checked:= not Checked;
end;
procedure Form1.CheckBoxKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_SPACE then
with TCheckBox(Sender) do
Checked := not Checked;
end;
저도 자료실에 얻어서 잘쓰고 있는 모듈입니다....
스페이스바나 마우스 클릭이벤트 둘다 먹습니다...
// * 스트링그리드내에 체크 박스를 넣는 모듈....
procedure Form1.Set_CheckBox;
Var
i : integer;
begin
for I := 1 to StringGrid1.RowCount-1 do
begin
StringGrid1.Objects[1,i] := TCheckBox.Create(StringGrid1);
with TCheckBox(StringGrid1.Objects[1, i]) do
begin
OnKeyUp := CheckBoxKeyUp;
OnMouseUp := CheckBoxMouseUp;
Parent := StringGrid1;
BoundsRect := StringGrid1.CellRect(1, i);
Width := StringGrid1.ColWidths[1];
Height := StringGrid1.RowHeights[1];
Checked := True;
end;
end;
end;
procedure Form1.CheckBoxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
with TCheckBox(Sender) do
Checked:= not Checked;
end;
procedure Form1.CheckBoxKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_SPACE then
with TCheckBox(Sender) do
Checked := not Checked;
end;