Answer the question
In order to leave comments, you need to log in
How to make automatic generation of buttons for the form by getting data from the database.Visual Studio 2013.C#, CSharp?
I am writing a small program in C# - Visual Studio'13.
The task is this.
How can I implement automatic generation of buttons in the form by getting data from the database?
Answer the question
In order to leave comments, you need to log in
Are you sure that you have a problem with the creation of buttons? The button is needed so that the user can initiate some action. Let's say you received a set of 10,000 records from the database. Are you sure you want to show them to the user? Even if you show them to him, how are you going to react to pressing the 7602 button?
@newross gave the correct answer to your question. But perhaps you should think about what problem you are actually solving. You may not need to generate buttons based on data from the database.
Just create new buttons and add them to the form like this
List<Button> buttons = new List<Button>();
for (int i = 0; i < 10; i++)
{
Button newButton = new Button();
buttons.Add(newButton);
this.Controls.Add(newButton);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question