>請教各位先進,我應如何限制在 TCheckListBox 中最多只能選三個 Items?
試試這個:
在 CheckListBox1 的 OnClickCheck 事件中撰寫下列程式碼:
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
var
i, cnt: integer;
begin
cnt := 0;
for i := 0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked[i] then
cnt := cnt+1;
end;
if cnt > 3 then
begin
ShowMessage('您只能有三個願望!');
CheckListBox1.Checked[CheckListBox1.ItemIndex] := false;
end;
end;
               (
geocities.com/huanlin_tsai)