2017-05-09 12 views
1

私はCheCkListBoxで私の選択肢を制限する必要があります。 リストからの選択肢は2つまでです。 どうすればいいですか?チェックされた項目の私はCheckListBoxで私の選択を制限する必要があります

procedure TForm1.RadioGroup1Click(Sender: TObject); 
begin 
    case RadioGroup1.ItemIndex of 

    0: begin 
     // No more than two selections from the list 
     end; 


    1: begin 
     // Choice not limited 
     end; 
    end; 
end; 

答えて

2

取得数:

function GetCheckedCount(const Cl : TCheckListBox) : Integer; 
var 
    I: Integer; 
begin 
    Result := 0; 
    for I := 0 to Cl.Count - 1 do 
    begin 
    if Cl.Checked[i] then 
     inc(Result); 
    end; 
end; 

CheckListBox OnClickCheckEvent:

procedure TForm13.CheckListBox1ClickCheck(Sender: TObject); 
const // or global variable or ... 
MaxCheckedItems = 2; 
begin 
    if GetCheckedCount(CheckListBox1) > MaxCheckedItems then 
    CheckListBox1.Checked[CheckListBox1.ItemIndex] := False; 
end; 
+0

はどうもありがとうございました – abrakadabra

関連する問題