【Delphi checklistbox的简单用法】

 

procedure TDcpMain.N1Click(Sender: TObject);  //删除选中行
begin
   //cxListBoxmovie.Items.Delete(cxListBoxmovie.ItemIndex);//只能删除单行
   cxListBoxmovie.DeleteSelected;//删除单行也可以删除多行
end;


procedure TDcpMain.N2Click(Sender: TObject); //全部选择
begin
if cxListBoxmovie.Items.Count-1>-1 then
  begin
    cxListBoxmovie.Selected[0]:=True;
    cxListBoxmovie.SelectAll;
  end;
end;

 

procedure TDcpMain.ButtonupClick(Sender: TObject); //上移
var
  ActiveItem: Integer;
begin
  with cxListBoxmovie do
  begin
    ActiveItem := ItemIndex;
    if (ItemIndex > 0) then
    begin
      Items.Move(ItemIndex, ItemIndex - 1);
      cxListBoxmovie.SetFocus;
      cxListBoxmovie.Selected[ActiveItem - 1] := True;
    end;
  end;

end;

procedure TDcpMain.ButtondownClick(Sender: TObject); //下移
var
  ActiveItem: Integer;
begin
  with cxListBoxmovie do
  begin
    ActiveItem := ItemIndex;
    if (ItemIndex >= 0) and (ItemIndex < Items.Count - 1) then
    begin
      Items.Move(ItemIndex, ItemIndex + 1);
      cxListBoxmovie.SetFocus;
      cxListBoxmovie.Selected[ActiveItem + 1] := True;
    end;
  end;
end;

 

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

再创世纪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值