I am trying to create a POS system (very basic one) in C# and I have products in a MYSQL database that I want to be pulled and then displayed in the system.
I can generate the buttons with the names no problem, the problem I have is that I want to implement a way for the user to click a button and it adds it into a list box - this is easy enough to do if I know the amount of products in the database but I won't so I need the onclick handler to be programmatically generated with the buttons
here is my button generation code:
int i = 1;
while (sqlReader.Read())
{
//Create label
var button = new Button {Text = String.Format(sqlReader.GetString("productName"), i)};
//Position label on screen
button.Left = 110;
button.Top = (i + 1)*30;
//Add controls to form
Controls.Add(button);
i++;
}
I realise not all of it is there but that's the while loop I am using to generate the buttons so I am wondering if the handler would go in there?