如果在CheckedListBox中检出任何内容,检查的代码是什么。我正在制作一个注册电影的应用程序,我需要检查来自CheckedListBox的电影类型。如果没有检查,应该会出现一个MessageBox,告诉您需要为电影选择一个类型。
发布于 2013-01-09 10:20:06
您应该根据需要检查CheckedItems或CheckedIndices属性。
CheckedListBox cl = new CheckedListBox();
if (cl.CheckedIndices.Count == 0)
{
MessageBox.Show("You need to select a Genre for the movie.");
}发布于 2013-01-09 10:23:09
您只需使用SelectedIndex属性:
if(checkListBoxGenre.SelectedIndex == -1)
{
MessageBox.Show("You need to select a Genre for the movie.");
}另一个选项是使用 property,它获取ListBox中当前选定项的文本。
if(checkListBoxGenre.Text.Length == 0)
{
MessageBox.Show("You need to select a Genre for the movie.");
}这只是一个可读性和个人喜好的问题。
发布于 2013-01-09 10:20:51
if(checkedListBox1.CheckedItems.Count != 0)
{
// If so, loop through all checked items and print results.
}
else
{
MessageBox.Show("You need to select a Genre for the movie.");
}https://stackoverflow.com/questions/14232916
复制相似问题