delphi - 我需要限制我在 CheckListBox 中的选择

标签 delphi

我需要限制我在 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;

最佳答案

获取已检查项目的数量:

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;

关于delphi - 我需要限制我在 CheckListBox 中的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43866029/

相关文章:

delphi - MadExcept + try/finally block ?

delphi 5 应用程序在 win7 x64 的面板上显示错误

Delphi 2009 和 Firebird 2.1 = 完整的 Unicode?

Delphi IFilter 实现

delphi - 仅具有进程ID时关闭主应用程序窗口的问题

image - 如何正确添加资源(*.res)文件到组件包中?

string - Delphi-如何搜索不完整的字符串匹配项

delphi - 如何将标准 Windows 信息图标很好地绘制到页面控件选项卡的索引

delphi - 如何获得正确的逻辑处理器数量

delphi - 如何改变 TBitBtn 的背景颜色?