1
I have a checkedListBox in a form tabControl. In the checkedlListBox there are several items that can be selected.
When the user clicks on the button below the checkedListBox, a loop is launched that checks whether or not they have selected items, if any, the user is redirected to another tabPage.
If you have not selected an option, Messagebox appears. But the big problem is that only for the first checkedListBox item.
If the second or third is selected and etc, Messagebox appears as if the user had not selected anything.
Then, returning to the title: how to go through all the items of a checkedListBox?
Code that is working with the first item:
private void btnEditarValores_Click(object sender, EventArgs e)
{
for (int i = 0; i <= (ListBoxSAdicionais.Items.Count - 1); i++)
{
if (ListBoxSAdicionais.GetItemChecked(i))
{
this.tabControl1.TabPages.Add(dados3);
this.tabControl1.SelectTab(2);
break;
}
else if ((ListBoxSAdicionais.GetItemChecked(i) == false))
{
MessageBox.Show("Você deve selecionar algum Status Adicional para editar os valores.");
break;
}
}
wouldn’t be the break inside if the problem?
– Pablo Tondolo de Vargas
When the user is redirected to tabPage(data3) the Messagebox of the other if should not appear and if I take the break from the first if, it keeps appearing. If I break Else if, you’ll be sending Messagebox until the loop goes through the amount of items in the checkedListBox. I’ve tried to remove the alternating breaks, it doesn’t work.
– Wevelly Felipe