Delete section of streamreader
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2010-04-21T08:09:45Z
Indexed on
2010/04/21
8:13 UTC
Read the original article
Hit count: 366
c#
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?
© Stack Overflow or respective owner