Hello all, I'm still fairly new to C# and I'm working on an issue in one of my assignments. I've successfully been able to read a text file into my code and transfer the list into a listbox. that was just for testing purposes. Then I was able to generate the same amount of buttons for each item from the text file into a panel. However I cannot seem to get the names of the items to become the text in the buttons and then to assign each button/name to the correct value to then do calculations. I'm not sure if I'm trying to combine two completely different ways of approaching this outcome but any help would be appreciated.
What I have tried:
this is the form class with the form load method
public Form1()
{
InitializeComponent();
}
List<appliances> allEntry = new List<appliances>();
public void Form1_Load(object sender, EventArgs e)
{
allEntry = ApplianceDA.GetAppliances();
DisplayButtons();
}
public void DisplayButtons()
{
int product = 0;
int startTop = 10;
int startLeft = 10;
foreach (Appliances ap in allEntry)
{
Button appButton = new Button();
this.Controls.Add(appButton);
appButton.Text = ("");
appButton.Location = new System.Drawing.Point(startTop + (125 * product), startLeft);
appButton.Height = 58;
appButton.Width = 120;
//appButton.Click += AButton_Click();
pnlBox.Controls.Add(appButton);
product++;
}
}
and here is the ApplianceDA class that reads the text file
static class ApplianceDA
{
private const string PATH = "Appliances.txt";
public static List<appliances> GetAppliances()
{
List<appliances> appliance = new List<appliances>();
StreamReader textIn = new StreamReader(new FileStream(PATH, FileMode.OpenOrCreate, FileAccess.Read));
while (textIn.Peek() != -1)
{
string row = textIn.ReadLine();
string[] columns = row.Split(',');
Appliances product = new Appliances(columns[0], Convert.ToInt64(columns[1]));
appliance.Add(product);
}
textIn.Close();
return appliance;
}