O
O
OmarFirst2014-10-27 17:27:15
Database
OmarFirst, 2014-10-27 17:27:15

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

2 answer(s)
A
aush, 2014-10-28
@OmarFirst

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.

A
Artem Voronov, 2014-10-27
@newross

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);   
    }

Accordingly, set the parameters obtained from the database to the buttons.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question