tchecklistbox

Limiting checked items of TCheckListBox on Delphi

依然范特西╮ 提交于 2019-12-02 01:14:39
问题 I want to limit a TCheckListBox. I desire only 2 items should be checked, and all unchecked items will be disabled and grayed. Since the checked / unchecked items are dynamic, i can not use a static itemIndex. Here is what i tried, but i got "Out of chip bounds" error. On click event of my CheckListBox ; var NumberOfCheckedItems, I: Integer; begin NumberOfCheckedItems := 0; for I := 0 to CkLst1.Count - 1 do begin if CkLst1.Checked[I] then NumberOfCheckedItems := NumberOfCheckedItems + 1; end;

Limiting checked items of TCheckListBox on Delphi

让人想犯罪 __ 提交于 2019-12-01 22:31:24
I want to limit a TCheckListBox. I desire only 2 items should be checked, and all unchecked items will be disabled and grayed. Since the checked / unchecked items are dynamic, i can not use a static itemIndex. Here is what i tried, but i got "Out of chip bounds" error. On click event of my CheckListBox ; var NumberOfCheckedItems, I: Integer; begin NumberOfCheckedItems := 0; for I := 0 to CkLst1.Count - 1 do begin if CkLst1.Checked[I] then NumberOfCheckedItems := NumberOfCheckedItems + 1; end; if NumberOfCheckedItems > 1 then begin CkLst1.Checked[I] := Enabled; CkLst1.Enabled := FALSE; CkLst1