Need file read in from form load
- by Luke
I am using a listview, and trying to populate using a file.
I need the file to be read in as soon as the form starts.
private void mainForm_Load(object sender, EventArgs e)
{
//get file read in
if (File.Exists("../../MealDeliveries.txt"))
{
StreamReader sr = new StreamReader("../../MealDeliveries.txt");
//first line is delivery name
string strDeliveryName = sr.ReadLine();
do
{
//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();
//stop if no more values
} while (strDeliveryName != null);
displayDeliveries();
}
}
Should this work?