Delete section of streamreader
- by Luke
I am reading a file into my program using streamreader.
private void loadFile()
{
lstDeliveryDetails.Items.Clear();
if (!File.Exists("../../MealDeliveries.txt"))
{
MessageBox.Show("File not found!");
return;
}
using (StreamReader sr = new StreamReader("../../MealDeliveries.txt"))
{
//first line is delivery name
string strDeliveryName = sr.ReadLine();
while (strDeliveryName != null)
{
//other lines
Delivery d = new Delivery(strDeliveryName, sr.ReadLine(),
sr.ReadLine(), sr.ReadLine(),
sr.ReadLine(), sr.ReadLine(),
sr.ReadLine());
mainForm.myDeliveries.Add(d);
//check for further values
strDeliveryName = sr.ReadLine();
}
}
displayDeliveries();
}
Eventually I end up with all the deliveries in the following array
public static ArrayList myDeliveries = new ArrayList();
It is loaded into the listview. I select an item as follows:
iDeliverySelected = lstDeliveryDetails.SelectedItems[0].Index;
I am struggling to understand how I can select an item and use a delete button to remove it from the text file?