delphi checklistbox用法


在Delphi中checklistbox中高亮選中(不論是否Checked)能夠進行操作么?刪除,上下移動等等

 

刪除: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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM