以下是我对动态添加的CheckBox到CheckBoxList的代码:动态添加的CheckBox到CheckBoxList的不显示文本
foreach (WCore.CategoryFields cat in Global.getCategories())
{
CheckBox c = new CheckBox();
c.Text = cat.CategoryId;
c.Tag = cat.CategoryName;
if (ints != null)
{
if (ints.Contains(c.Tag))
Invoke(new Action(()=>checkedListBox1.Items.Add(c, true)));
else
Invoke(new Action(()=>checkedListBox1.Items.Add(c, false)));
}
else
Invoke(new Action(()=>checkedListBox1.Items.Add(c, false)));
}
的问题是,每当我运行此代码,复选框被添加,但不与文本。就像这样:
我试图调试它,然后我发现,CheckBox实例“C”越来越文本,但不显示它。
在这里看到:
请告诉我什么是错在这段代码怎么回事?
UPDATE
请注意,我不能这样使用它:
Invoke(new Action(()=>checkedListBox1.Controls.Add(c)));
因为它能够更好地使用面板,而不是CheckBoxList的然后。 此外,我想两个值一个显示为文本和其他隐藏的价值为每个复选框中的CheckBoxList
更新2
代码获取所选项目:
List<string> SelInts = new List<string>();
foreach (ListBoxItem c in checkedListBox1.SelectedItems)
{
SelInts.Add(c.Tag.ToString());
}
我想你的意思是你想让'checked items'不是'selected items'? –
雅谢谢,改变那工作:) –