I have a small form in which the user writes the name of some item, and then when he clicks “Add” there is a statement that needs to check if there is already the same item in the checkedListBox.
I’m looking for the “if” statment that checked if the list is empty or with some item.
private void button2_Click(object sender, EventArgs e)
{
foreach (var item in checkedListBox1.Items)
{
if (itemName.Text == item.ToString())
{
DialogResult result = MessageBox.Show("?", "Question", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
checkedListBox1.Items.Add(itemName.Text);
}
else if (result == DialogResult.No)
{
//clear the forms
}
}
else
{
checkedListBox1.Items.Add(itemName.Text);
timeLeft = 2;
timer1.Start();
}
}
}
//checkedListBox1.Items.Add(itemName.Text);
//timeLeft = 2;
//timer1.Start();
EDIT:
is for checking if the CheckedListBox is empty or not, then
is to check if an item is already in the CheckedListBox.