我的代码中有一个简单的 IF 语句,如果选中了我的 checklistbox1 的索引 2 中的项目,我想提示用户。
它在单独选择索引 2 时起作用,但在我的 list 框中选中包括索引 2 在内的其他项目时不起作用。下面是我的作品,现在我只需要它在选择 2 和其他人时工作。
if (checkedListBox1.SelectedIndex == 2)
{
MessageBox.Show("Note to send email", "Note", MessageBoxButtons.OK);
}
最佳答案
将该代码替换为
if (checkedListBox1.SelectedIndices.Contains(2))
{
MessageBox.Show("Note to send email", "Note", MessageBoxButtons.OK);
}
这将检查 2 是否在所有选定项目中。
在
SelectedIndices
上查看更多信息房产位于 MSDN .
关于c# - Checkbox Selected Index 被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20094389/