I have a program with 2 Forms on it. Essentially it is a program that will put data from a CSV file into a DataGrid
.
The first form has a ListBox
on it displaying several folders from a hard coded directory. My objective is to select one of my subdirectories on the ListBox
, then use a method to find a CSV file in this directory, and transfer all the data from the CSV file to the DataGrid
on my program.
Form 2 is designed to display the data from the CSV file onto a DataGrid
once I click a report button on Form 1. My code worked perfectly when I tested it out by using a temporary data grid on Form 1, but once I tried the same thing on Form 2 the DataGrid
just comes up empty??
I tested out Form 2's DataGrid
by hardcoding one of the paths right into it and it worked, I just cant seem to be able to take the string from my ListBox
on Form 1 and use it on Form 2??
Here is the string getting the text from Form 1's ListBox
:
public void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pPath = listBox1.GetItemText(listBox1.SelectedItem);
label1.Text = pPath; //Sets the Label to CsvPath
}
Here is the code from Form 2 that's supposed to display the data on Form 2' DataGrid
;
var reader1 = new StreamReader(File.OpenRead(GetCsvFile1(frm1.pPath)));
List<DateTime> listA_DateTime = new List<DateTime>();
List<string> listB_Location = new List<string>();
List<decimal> listC_Debt = new List<decimal>();
List<decimal> listD_Credit = new List<decimal>();
List<decimal> listE_Balance = new List<decimal>();
while (!reader1.EndOfStream)
{
string line = reader1.ReadLine();
string[] values = line.Split(',');
listA_DateTime.Add(Convert.ToDateTime(values[0], CultureInfo.InvariantCulture));
listB_Location.Add(values[1]);
if (values[2] == "")
{
listC_Debt.Add(0);
}
else
{
listC_Debt.Add(decimal.Parse(values[2]));
}
if (values[3] == "")
{
listD_Credit.Add(0);
}
else
{
listD_Credit.Add(decimal.Parse(values[3]));
}
if (values[4] == "")
{
listE_Balance.Add(0);
}
else
{
listE_Balance.Add(decimal.Parse(values[4]));
}
}
while (a < listA_DateTime.Count)
{
this.dataGridView1F2.Rows.Add(listA_DateTime[a].ToShortDateString(), listB_Location[a], listC_Debt[a], listD_Credit[a], listE_Balance[a]);
a++;
}
Thanks in advance for any help that can be given.