1. 程式人生 > 其它 >Delphi CheckListBox用法 文章來源於《傻貓網路日誌》 https://www.samool.com/41856.html

Delphi CheckListBox用法 文章來源於《傻貓網路日誌》 https://www.samool.com/41856.html

CheckListBox如何設定行高?
預設設定是 lbStandard 或者 lbOwnerDrawVariable 會忽略你的行高設定值的
改為lbOwnerDrawFixed 屬性即可

刪除:CheckListBox.DeleteSelected;
上下移: CheckListBox.Items.Move

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

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

//在專案中新增字串(子專案的最後一位接著新增)

  CheckListBox1.Items.Add(edit1.Text); 

//全選 高亮選中Selected

 CheckListBox1.MultiSelect := True;
 CheckListBox1.SelectAll;

//全選 Checked All
procedure TForm1.Button11Click(Sender: TObject);
var i :integer;
begin
for i := 0 to CheckListBox1.Items.Count - 1 do

begin
  CheckListBox1.Checked[i] := True;//反選設定為False
end;

end;

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

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

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

//刪除高亮選中的專案,(只管高亮選中就會被刪除,和checked是否無關)

    CheckListBox1.DeleteSelected;//刪除選中專案,即使該給專案 沒勾上也會被刪除

//刪除已勾選的中專案
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;



文章來源於《傻貓網路日誌》 https://www.samool.com/41856.html