views:

1416

answers:

7
+2  A: 

You'll have to post some of the layout code or we won't be able to help much/at all.

Also, your #1 best bet is to profile your code. Profiling is the only surefire way to find out what exactly is performing slowly in your code. In my experience, this is especially true of UI code.

JaredPar
Should I post the layout code here in the comments?flowLayoutPanel1.SuspendLayout();foreach(DataRow row in dt.Rows){flowLayoutPanel1.Controls.Add(new PersonButton(row));}flowLayoutPanel1.ResumeLayout();That's the only custom code. Except the PersonButton constructor which alters the labels.
aidan
I would update the main question.
JaredPar
+14  A: 

Can a C# WinForm app handle 1000 instances of any type of control? I am no WinForm Guru, but what you are expecting from your application might be unreasonable.

The fact that you want to show 1000+ controls of any type might be a sign that you are approaching the design of your software from the wrong direction.

Matthew Ruston
I was worried that would be the answer :)
aidan
Agreed! Why would you want to display 1000 controls on a form?
Rune Grimstad
+1 Matthew, how can a user be expected to keep track of 5000 different buttons?
scottm
+1. This falls under Raymond Chen's "If you have to ask, you're probably doing it wrong" rule: http://tinyurl.com/d27sdt. Usability is key: There's pretty much never a reason to display 1000+ controls on a page. That much data WILL overwhelm the user.
John Rudy
A: 

What you're doing wrong? You are creating thousands of controls. There is probably a better way to do what you try to do.

erikkallen
+1  A: 

At 1000+ buttons your probably running perilously low on GDI resources and/or raw handles for your application.

Not sure what your application is supposed to do but a grid or a combo box may be the better option here.

mjmarsh
+1  A: 

It sounds like you seriously need to rethink your interface.

Like others have mentioned, that number of controls on a form will not be usable.

However I have done some experimenting looking at time to create new controls in code, even using reflection, and found that several hundred data-bound controls created on the fly in a flow-layout panel should be created in 1 to 2 seconds.

Posting more code samples may help get a better answer.

More info: I have just rerun my timing test again, 300 controls took 0.5 seconds, 400 took 1.9 seconds, 600 took 3 seconds, 1000 took 6 seconds.
It seems that there is a limit somewhere between 300 and 400 where resources start to get over utilised.

benPearce
+1  A: 

The layout logic required for 5k controls will be too much for any type of wrapping panel. You might want to look into a different type of control designed the hold thousands of entries - something like a DataGridView.

The DataGridView has several different column types available that should work for the type of data you're displaying (images, buttons, labels). Since your database query looks to return a DataTable, you could simply bind that directly to your DataGridView and remove the loop.

The Reddest
A: 

Try to use Page navigation concept

Waleed