DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Adding controls smoothly...  (Read 7,048 times)

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
Adding controls smoothly...
« on: August 28, 2012, 01:31 PM »
Okay so I am writing a program that has to load a lot of information from MySql then add it to controls.

Get Data > Fill Control > Display Control

Only problem is I could be loading as few as 4 controls or as many as 1000. Is there a better way I can add everything? It works for now but is not pleasant to watch and would defiantly not be good for a consumer to see. I have tried loading the controls before the form is loaded but that didn't work so well, also tried Control.SuspendLayout(); and Control.ResumeLayout(); Still no good.

If anyone has any ideas I will be will to try anything to get this working 100%

Many thanks

*Edit* Forgot to mention I am programming on C#
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka

Renegade

  • Tell me something you don't know...
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
    • Participated in NANY Challenge Three Times
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: Adding controls smoothly...
« Reply #1 on: August 28, 2012, 02:15 PM »
Well, it depends on what control that you are loading to a large degree.

If you seriously want to dive into the VERY deep end, I recommend buying the Infralution Virtual Tree control as it does dynamic loading, and could give you some insight into how to do what you're asking.

However, if you're loading 1000 controls, I think you have a very serious design flaw. Why would you want to do that? I really have no idea what you're trying to accomplish, so without more details, I'm afraid that I can't be of much help.

Still, if you want to do it like that...

Do it in threads. Have an update that lets the user know what's going on. Create all the controls. Fill them. Return them. Add them to the UI in a Panel control (or whatever - I'm assuming a Panel is best there). Return control of the application to the user when it's finished or they click a "Cancel" button or a "Stop" button. (I'd use "Stop" to mean "that's enough for now".)

If you can post more details, maybe I or someone else can chime in with some better information. Until then, look into threading as that will likely solve your problems.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
Re: Adding controls smoothly...
« Reply #2 on: August 28, 2012, 02:24 PM »
Well not literally 1000 but it has no limit on the amount... I would say generally about 20-30 controls... I will look into threading though.

[Header]
{info}
{info}
[Header]
{info}

Header is not a problem since it is just the Header and doesn't really load any info

Info loads info from 1 row and about 5 columns from MySql for each (2 picture boxes, 3 linklabels, 3 labels)
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka

fenixproductions

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,186
    • Participated in NANY Challenge Four Times
Re: Adding controls smoothly...
« Reply #3 on: August 28, 2012, 02:30 PM »
I had investigated such issue long ago and there was no solution for multi-control forms. SuspedLayout is the most popular/answered one but it does not help too much.
There is also double buffering solution which also has some troubles.

The only thing which helped (from user perspective) was to "make screen busy"  - according to an advice from MS site I read very long ago.
So… build eveything in background and show waiting animation during that.
Надо было учиться, а не камни в школу бросать...
--
f0dder is my personal hero :)

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Adding controls smoothly...
« Reply #4 on: August 28, 2012, 02:33 PM »
Use the databinding features of .NET, it will lazy-load by default (afaik) when loading lots of controls, and it'll fetch & display 'Just In Time', when using controls like comboboxes etc. Using WPF for the UI might help too.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
Re: Adding controls smoothly...
« Reply #5 on: August 28, 2012, 02:46 PM »
I will try the databinding although never really been able to work with it properly lol

As for wpf I will have to look into it :)

Thanks for the reply's got a fair idea of how to do this and make it smooth and look good :)
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka

Original address: https://www.donationcoder.com/forum/index.php?topic=32076.0