In my form have TextBox1 and ListBox1, buttonAdd, buttonRemove
buttonAdd => OK, I can do it. buttonRemove: When you delete a section: - Delete entry from textbox: Check one item in the listbox item should be deleted, if there are clear, if not, the message is not found - Delete the selected item in listbox
This is my idea:
private void butonRemove_Click(object sender, EventArgs e)
{
if (textbox1.Text != "")
{
int i = 0;
while (i <= listbox1.Items.Count)
{
string Item_remove = textbox1.Text;
if (listbox1.Items[i].ToString().Contains(Item_remove))
{
DialogResult conf_remove;
conf_remove = MessageBox.Show("Do you wwant to remove: " + listbox1.Items[i].ToString(), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (conf_remove == DialogResult.Yes)
{
listbox1.Items.RemoveAt(i);
break;
}
else if (conf_remove == DialogResult.No)
i++;
}
else
{
MessageBox.Show("Not found");
break;
}
}
textbox1.Text = "";
textbox1.Focus();
}
else if (listbox1.SelectedIndex < 0)
MessageBox.Show("Please select item to remove");
else
listbox1.Items.Remove(listbox1.SelectedItem);
}
Please help me fix it, thank