I am working on a C# application where when a form loads, I want it to read in the contents of a txt file and store it to an array. Next, when a click a button on the form, I want the button click event to access the array. How do I pass the array to the button click event? My code below has an error "statusArray does not exist in current context" and is related to the reference to the array in the button click event. What do I need to do?
Susan
private void btnCompleted_Click(object sender, EventArgs e)
{
for (int i = 0; i < statusArray.Count; i++)
{
if (statusArray[i].Equals("Complete"))
lstReports.Items.Add(statusArray[i-2]);
}
}
private void Reports_Load(object sender, EventArgs e)
{
// declare variables
string inValue;
string data;
ArrayList statusArray = new ArrayList();
inFile = new StreamReader("percent.txt");
// Read each line from the text file
while ((inValue = inFile.ReadLine()) != null)
{
data = Convert.ToString(inValue);
statusArray.Add(inValue);
}
// Close the text file
inFile.Close();
}