Avoiding a large number of user controls in the form

I am creating a user control that presents a list of other custom controls (they are pretty simple: include a label, checkbox, icon, and button). When I put it on the form, it takes a long time to load all the elements of the list (in the list of 100 - 150 elements). What are the alternative ways to display a list of user controls for a large number?

I tried using SuspendLayout and ResumeLayout, but it didn’t help, using them reduces the time, but it is still too long.

There are several ideas that I cannot implement for various reasons:

  • somehow only work with elements that fall into the view (how to ignore others?)
  • implements grid control behavior - create a custom control only in edit mode, but it's hard to draw others.

Grateful for any advice

EDIT:

There were several suggestions for using a DataGridView. This is a good idea, but the problem is that the user control can resize it and show additional information below (it behaves like an extender). This is not easy to do with a DataGridView.

+4
source share
4 answers

I agree with @Cody, but in case "removing some of the ones you have" is not an option ... let me take it one step further ...

You mentioned that you have a list.

I would recommend from the iOS playlist, and only the number of active controls that you need to display on the screen.

For instance; If the list has space for 30 items on the screen, you can reuse the same 30 controls that the user scrolls / pages through the list.

Which brings up another point - sometimes a small change in navigation is a good bet. If you now have one huge list, perhaps the β€œswap” functions, in which you show only x the number of elements per page, this is what you need to consider.

No matter when you get to this point in the application, and you have real requirements for download speed / memory performance, it's time to crack the old performance tuning book and implement proven models such as reuse, caching, etc. Usually this is not always beautiful, and it makes your decision more complicated, but you do what you need to do to make it work correctly.

+1
source

If you are attached to WinForms, I highly recommend that you use DataGridView instead. I ran into the same problems a while ago and found that the DataGridView is extensible enough to list all kinds of controls (TextBoxes, CheckBoxes, even DateTimePickers, etc.). The transition to this control significantly accelerated my interface and was more stable and easier to maintain.

If you need more advanced tools on each line, for example the Expander properties mentioned above, then I think you should look into WPF. With WPF, you have tremendous flexibility to completely design your user interface controls the way you want, and performance is still very good.

If none of them work for you, then what about redesigning your user interface? As already mentioned, there is no way to ease the performance hit for a large number of controls. So, what about displaying one row or just a few rows at a time, with a filter or search tool that allows the user to find the rows that they want. Or, show all the lines, but use only the minimum controls on each line and ask the user to double-click the line to open a dialog box to display more detailed information about the line? One way or another, you will have to reduce the number of initially displayed controls. These are just a few ideas.

+2
source

Unfortunately, there is no way to get something for nothing. Things in life do not come for free. If you have an unreasonable number of controls in your form, you will have to pay for the time required to download them. The only option is to use fewer controls.

Whether you achieve this by removing some of the ones that you have from, or by custom drawing lighter versions of the built-in peers, is up to you. But I highly recommend that you stick with the built-in controls and just cut a few of the ones you are using now.

In addition to the obvious performance issues, the script you described is guaranteed to create a user overflow error, one that the debugger cannot fix.

+1
source

Use DataGridView and customize columns?

0
source

All Articles