hex*_*x c 2 c# indexing checkbox foreach panel
我正在尝试检查我的panel1中检查的每个复选框.然后显示在label1中检查的项目.我无法使用面板和复选框...下面是我的代码.任何建议都会很棒!谢谢
foreach (int indexChecked in panel1)
{
str1 += panel1.Items[indexChecked].ToString() + ", ";
label1.Visible = true;
}
label14.Text = str1;
Run Code Online (Sandbox Code Playgroud)
Sud*_*udi 11
解决方案1:
String str1="";
foreach (Control c in panel1.Controls)
{
if((c is CheckBox) && ((CheckBox) c).Checked)
str1 += c.Text+ ", ";
}
str1=str1.Trim();
str1=str1.Substring(0,str1.Length-1);
label14.Text = str1;
Run Code Online (Sandbox Code Playgroud)
解决方案2: 如果要将每个选中的CheckBox项添加到ListView
试试这个:
listView1.Items.Clear();
foreach (Control c in panel1.Controls)
{
if((c is CheckBox) && ((CheckBox) c).Checked)
listView1.Items.Add(c.Text);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21178 次 |
| 最近记录: |