【发布时间】:2021-03-13 16:06:51
【问题描述】:
我有三个复选框,选择后可以在列表框中输入一个条目(见下文)。当我想更改复选框的状态(未选中)时,如何再次从列表框中删除条目?非常感谢您的所有帮助!
private CheckBox[] checkboxes;
private string[] cbx;
checkboxes = new[] {checkBox1, checkBox2, checkBox3};
checkBox1.Tag = "string1";
checkBox2.Tag = "string2";
checkBox3.Tag = "string3";
foreach (var checky in checkboxes)
{
checky.CheckedChanged += CheckBox_CheckedChanged;
}
private void CheckBox_CheckedChanged(object sender, EventArgs e)
{
cbx = checkboxes.Where(checky => checky.Checked)
.Select(checky => checky.Tag)
.Cast<string>()
.ToArray();
listBox4.Items.AddRange(cbx);
}
【问题讨论】: