cxCheckCombobox里实现checked和获取Itemindex
今天用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
📱 扫码关注公众号
扫描二维码关注我们,获取更多精彩内容
实时更新 · 干货满满