Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 03, 2016, 09:59:08 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Adding controls smoothly...  (Read 2153 times)

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Adding controls smoothly...
« on: August 28, 2012, 08:31:47 AM »
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

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Adding controls smoothly...
« Reply #1 on: August 28, 2012, 09:15:03 AM »
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
    • View Profile
    • Donate to Member
Re: Adding controls smoothly...
« Reply #2 on: August 28, 2012, 09:24:54 AM »
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,184
    • View Profile
    • Donate to Member
Re: Adding controls smoothly...
« Reply #3 on: August 28, 2012, 09:30:56 AM »
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.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,778
    • View Profile
    • Donate to Member
Re: Adding controls smoothly...
« Reply #4 on: August 28, 2012, 09:33:00 AM »
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.

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Re: Adding controls smoothly...
« Reply #5 on: August 28, 2012, 09:46:50 AM »
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