My goal is that when the user removes an item from a Listbox
, the program deletes a particular line from a file.
I have this text in a file .txt
:
linha1
linha2
linha3
No Listbox
contains the contents of the .txt
file, I want when the user deletes a specific line, also delete the file.
If the user deletes "line2" the file .txt
should look like this:
linha1
linha3
I have this code so far:
//delete ListItemsBox Selected Item
private void ListItemsBox_DoubleClick(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + "MyTest.cs";
if (ListItemsBox.SelectedItem.Equals("When Start"))
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this item?All items will be deleted including all files!", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
ListItemsBox.Items.Clear();
File.Delete(path);
btnWhenStart.Show();
End.Show();
}
else if (dialogResult == DialogResult.No)
{
}
}
else
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this item?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
ListItemsBox.Items.Remove(ListItemsBox.SelectedItem);
}
else if (dialogResult == DialogResult.No)
{
}
}
}
The problem I am facing is that I do not know how to do it and I do not understand some tutorials that appear to me.