Q&A

  • StringGrid에 CheckBox구현에 문제점 해결해 주세요...
체크박스를 동적으로 생성하다 보니....

스트링 그리드에 0 칼럼, 0 로우에 체크박스가 원하지도 않은 자리에 체크박스가 생성이

됩니다.



-------------------------------------------------------

ㅁCheckbox | ColumnHeader1 | ColumnName2 | ColumnName3

_______________________________________________________

ㅁChecked

ㅁChecked

ㅁChecked



위와 같이 맨 왼쪽에 체크박스가 생성이고 원하는 체크박스가 생성이 됩니다.

왼쪽 맨 끝에 것을 없애려고 하는데 잘 안없어집니다...



제가 생성한 코딩은

Q & A를 참고로 해서 코딩을 했습니다..



for i := 1 to ag_main.RecordCount - 1 do

begin

OnKeyUp := CheckBoxKeyUp; //--> CheckBox이벤트 연결부분

OnMouseUp := CheckBoxMouseUp;

Parent := ag_main;

BoundsRect := ag_main.CellRect(9, i);

Width := ag_main.ColWidths[9];

Height := ag_main.RowHeights[9];

Checked := True;

Caption := 'Checked';

end;



procedure TMain.CheckBoxMouseUp(Sender: TObject; Button:

TMouseButton; Shift: TShiftState; X, Y: Integer);

var

i : Integer;

begin

with TCheckBox(Sender) do

Checked := not Checked;



for i := 1 to ag_main.rowcount-1 do

begin

with TCheckBox(ag_main.Objects[9, i]) do

begin

if Checked then Caption := 'Checked' else

Caption := '';

end;

end;



end;



procedure TMain.CheckBoxKeyUp(Sender: TObject; var Key: Word;

Shift: TShiftState);

var

i : Integer;

begin

if Key = VK_SPACE then

with TCheckBox(Sender) do



Checked := not Checked;



for i := 1 to ag_main.rowcount-1 do

begin

with TCheckBox(ag_main.Objects[9, i]) do

begin

if checked then Caption := 'Checked' else

Caption := '';

end;

end;

end;

0  COMMENTS