首页 Delphi 正文
  • 本文约1467字,阅读需7分钟
  • 2281
  • 0
举报该广告
cxCheckCombobox里实现checked和获取Itemindex

cxCheckCombobox里实现checked和获取Itemindex

摘要

今天用cxCheckCombobox,准备获取cxCheckCombobox里所有被checked的Items的Itemindex,通过个人的思考和从网络上获取的参考,用cxCheckCombobox实现以上功能主要有两种方法。如下:

uses

   cxLookAndFeelPainters;

………



var

  Form1: TForm1;

&nbs...

今天用cxCheckCombobox,准备获取cxCheckCombobox里所有被checked的Items的Itemindex,通过个人的思考和从网络上获取的参考,用cxCheckCombobox实现以上功能主要有两种方法。如下:

uses

   cxLookAndFeelPainters;

………



var

  Form1: TForm1;

  S : string;

implementation



{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);

var

  I : Integer;

begin

  S := '';

  for I := 0 to cxCheckComboBox1.Properties.Items.Count - 1 do

  begin

    if cxCheckComboBox1.States[I]=cbschecked then

    S := S + IntToStr(I);

  end;

  ShowMessage(S);

end;



procedure TForm1.Button2Click(Sender: TObject);

Var

  I : Integer;

begin

  S := '';

  for I := 0 to cxCheckComboBox1.Properties.Items.Count - 1 do

  begin

    if  cxCheckComboBox1.Properties.Items[I].Tag=1  then

    S := S + IntToStr(I);

  end;

  ShowMessage(S);

end;



procedure TForm1.cxCheckComboBox1PropertiesClickCheck(Sender: TObject;

  ItemIndex: Integer; var AllowToggle: Boolean);

begin

  if cxCheckComboBox1.Properties.Items[ItemIndex].Tag=0 then

    cxCheckComboBox1.Properties.Items[ItemIndex].Tag:=1

  else

    cxCheckComboBox1.Properties.Items[ItemIndex].Tag:=0;

end;



procedure TForm1.FormCreate(Sender: TObject);

Var

  I : Integer;

begin

  for I := 0 to cxCheckComboBox1.Properties.Items.Count - 1 do

  begin

    cxCheckComboBox1.Properties.Items[I].Tag :=0;

  end;

end;



注意:在判断cxCheckComboBox1.States[I]的状态时,一定要在uses里添加cxLookAndFeelPainters。该状态是一个枚举,有三个分别为;选中:cbsChecked ,不选中:cbsUnchecked,灰色:cbsGrayed


📱 扫码关注公众号

公众号二维码

扫描二维码关注我们,获取更多精彩内容
实时更新 · 干货满满

收藏

扫描二维码,在手机上阅读
评论
更换验证码
友情链接