2
My goal is that when the user removes an item from a Listbox
, the program delete a certain line from a file.
I have this text in a file .txt
:
linha1
linha2
linha3
In the Listbox
contains the contents of the file .txt
, I want that when the user deletes a specific line, delete also in the file.
If the user deletes "Linha2" 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 and do not realize some tutorials that appear to me.
I edited your question to make it clearer what you want. Note: In your code will only delete the line if it is "When Start" and not the selected line.
– stderr