A
A
Arbitr2017-10-07 20:59:03
C++ / C#
Arbitr, 2017-10-07 20:59:03

How to add controls programmatically in a loop?

There is a base where information is stored organizations, the name of the organization, its description, the name of its logo.
You need to display this information in the label, in one name, in the second description and logo, respectively, in the picturebox.
59d914d16c531850568537.png
How to create controls in a loop?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VoidVolker, 2017-10-07
@ArBitr_exe

string[] items = new string[]{ "Item 1", "Item 2", "Item 3" };
foreach(var item in items){
    new Label { Text = item };
}

A
Alexander Kuznetsov, 2017-10-08
@DarkRaven

In general, I would recommend making a UserControl that reflects the essence of the desired control from your image. Just "draw" as you like, add public properties for the name, description and log, where you will assign the appropriate values.
You can do it not through three properties, but through one property - a model in which these three properties are represented. And model to connect through DataBindings with controls.
Next, just load the data and create your controls in a loop, adding them, as you suggested in the first answer from VoidVolker

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question