CheckListBox1的使用

涂磊的小作,请赐教 / 2024-10-15 / 原文

var i:integer;
begin
    for I := 0 to CheckListBox1.Count -1 do
     if CheckListBox1.Checked[i]                 // 左边的 Check框 是否 勾中
     then  showmessage(CheckListBox1.Items[i] )  // 右边的 文本
end; 

var i:integer;
begin
    for I := 0 to CheckListBox1.Count -1 do
      if CheckListBox1.Selected[i] then  //Selected表示 右边 蓝色 项
        showmessage(CheckListBox1.Items[i] )
end

//删除高亮选中的项目,(只管高亮选中就会被删除,和checked是否无关)

 CheckListBox1.DeleteSelected;//删除选中项目,即使该给项目 没勾上也会被删除

//全选 高亮选中Selected 

 CheckListBox1.MultiSelect := True; CheckListBox1.SelectAll;

//让第n行被高亮选中
CheckListBox1.Selected[1]:=true;//第2行

//取消高亮选中
CheckListBox1.ClearSelection;


 

CheckListBox如何设置行高?

默认设置是 lbStandard 或者 lbOwnerDrawVariable 会忽略你的行高设置值的
改为lbOwnerDrawFixed 属性即可


全部Check    https://docwiki.embarcadero.com/CodeExamples/Sydney/en/CheckListBoxCheckAll_(Delphi)

CheckListBox1.CheckAll(cbChecked, false, true);
//全选 Checked All
procedure TForm1.Button11Click(Sender: TObject);
var i :integer;
begin
for i := 0 to CheckListBox1.Items.Count - 1 do 
 CheckListBox1.Checked[i] := True;//反选设置为False   
end;

全部unCheck

CheckListBox.CheckAll(cbUnchecked, true, false);

 


上下移: CheckListBox1.Items.Move

删除用
CheckListBox1.Items.Delete(Index);

上下移动用
CheckListBox1.Items.Move(CurrentIndex,NewIndex);

//在项目中添加字符串(子项目的最后一位接着添加)

 
 CheckListBox1.Items.Add(edit1.Text); 

 

 

//第3行的项目灰色不可用
CheckListBox1.ItemEnabled[2] := False;//True可用

 

 

//删除已勾选的中项目
procedure TForm1.Button5Click(Sender: TObject);
var i : integer;
begin
for i := CheckListBox1.Items.Count-1 downto 0 do //从后面往前面删
begin
if CheckListBox1.Checked[i] then

 
 begin CheckListBox1.Items.Delete(i); end;
 

end;
end;

//清空项目
CheckListBox1.Items.Clear;

//将CheckListBox1的全部添加到CheckListBox2的Items中
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
begin
CheckListBox2.Items.Clear;
for i := CheckListBox1.Items.Count - 1 downto 0 do
begin

 
 CheckListBox2.Items.Add(CheckListBox1.Items[i]);
 

end;
end;