// Load data
private void loadDataButton_Click(object sender, System.EventArgs e)
{
// show file selection dialog
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
StreamReader reader = null;
// read maximum 50 points
double[] tempData = new double[50];
try
{
// open selected file
reader = File.OpenText(openFileDialog.FileName);
string str = null;
int i = 0;
// read the data
while ((i < 50) && ((str = reader.ReadLine()) != null))
{
// parse the value
tempData[i] = double.Parse(str);
i++;
}
// allocate and set data
data = new double[i];
dataToShow = new double[i, 2];
Array.Copy(tempData, 0, data, 0, i);
for (int j = 0; j < i; j++)
{
dataToShow[j, 0] = j;
dataToShow[j, 1] = data[j];
}
}
catch (Exception)
{
MessageBox.Show("Failed reading the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
finally
{
// close file
if (reader != null)
{
reader.Close();
}
}
// update list and chart
UpdateDataListView();
chart.RangeX = new Range(0, data.Length - 1);
chart.UpdateDataSeries("data", dataToShow);
chart.UpdateDataSeries("solution", null);
// set delimiters
UpdateDelimiters();
// enable "Start" button
startButton.Enabled = true;
}
}