I'm used to working with HTML apps in which there is no problem of creating a list of components (like phonebook contact).
Now I have used this method in Windows Forms. One panel is populated with large number of custom UserControls (UC). Only 30 UserControls takes more than 5s to render. While the list of data from database is returnd in <1s.
This UC has only labels, PictureBox and Click event. It's called like this. This data is used to populate child controls.
new UserControl(MyModel data);
Is there a beter way of doing this? I would like to have user friendly GUI and not using Grid layout. It's not user friendly and very limited in terms of how data can be showed to user.
foreach (var data in myDbResult)
{
var uc = new MyUserControl(data);
uc.Dock = DockStyle.Top;
resultFlowPanel.Controls.Add(uc);
}
...
public MyUserControl(MyModel data)
{
this.data = data;
InitializeComponent();
label1.Text = data.name;
label2.Text = data.address;
// get some more data from database
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["AlarmDbCon"].ConnectionString))
{
payer = db.Query<Models.g_UserPayer>("SELECT TOP(1) * FROM g_UserPayer WHERE ID_User=@UserID", new
{
UserID = guard.ID_User
}).FirstOrDefault();
}
label3.Text = payer.email;
PictureBox.Image = payer.image;
}