?
Solved

Screen flickering while adding items at runtime..

Posted on 2004-08-30
10
Medium Priority
?
288 Views
Last Modified: 2010-04-15
Hi,

In my application, I have a Panel control when I add controls at runtime, dock them on panel top....and populate them...the screen flickering occur....It looks like item stays at the top of the pannel for 3-4 seconds until it gets populated...How I can solve this issue...

Thanks for the help, nauman.
0
Comment
Question by:nauman_ahmed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 1

Expert Comment

by:CrazyIvan007
ID: 11933933
You can use

BeginUpdate()

at the Panel before adding the Controls, and then

EndUpdate()

But i think the problem is, that you run it all in the UI Thread, which will stop the UI for a while.

So you can let the Adding of the Controls run in a seperate Thread. For this you have to generate  a Delegate to Add the Controls to the UI (otherwise it's not Safe)

public delegate DelegateAddControl(System.Windows.Form.Panel pnl, Control ctrl);

public class yourapp
{
   private DelegateAddControl m_DelegateAddControl;
   Thread[] t_AddControl = new Thread[1];

   // after InitializeComponent();
   m_DelegateAddControl = new DelegateAddControl(this.AddControl);


   private void AddControl(System.Windows.Form.Panel pnl, Control ctrl)
   {
      pnl.Controls.Add(ctrl);
   }

   private void AddControl()
  {
      t_AddControl[0] = new Thread(new ThreadStart(this.AddControlThread);
      t_AddControl[0].Start();
   }

   private void AddControlThread();
   {
      // Create your Control
      this.Invoke(this.m_DelegateAddControl, new object[] { this.paneltoadd, _controltoadd });

       // more you want to add
    }

}
0
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 11935864
Thanks for the reply...Actually I am planning to program like this:

1. In Main form, I add controls on runtime depending on the user selection. This consist mostly on ListView.
2. I populate the list view using a class called UIDataManagement where I pass the ListView as a parameter.

Now where I should use a new thread? In UIDataManagement or in the MainForm? Also I tried to run an example based on your solution but it didn work...:(

-Nauman.
0
 
LVL 1

Expert Comment

by:CrazyIvan007
ID: 11936253
The Thread should run from the MainForm.

In the Thread you can add the ListViews and Populate them with the data. Otherwise you have to create new Threads for UIDataManagment.

Because you will change Controls in the UI Thread you have to use Delegate, otherwise it will be possible that your App throws Exceptions.

You can try it without Delegate, but it isn't Thread Safe. For more Information look at

http://www.google.de/search?hl=de&ie=UTF-8&q=c%23+delegate&meta=

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:somnatic
ID: 11939069
Don't even try it without .. Strange behaviours can occur (believe me .. i had to find that out by myself ... )

Even if you won't get exceptions, some things won't work properly ..
0
 
LVL 11

Accepted Solution

by:
Agarici earned 1000 total points
ID: 11942135
if you will use a thread to load the contents of the list, use contol.invoke to call the add function of the listview items collections.
otherwise you will get exceptions... even if it runs ok once, the second time may throw an exception...

btw, unless you have a realy huge list to load, creating another thread to load the items into the listview is not a good idea

hth.
A.
0
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 11943483
Thanks for the reply experts. Actually this application is an outlook 2003 style application with 5 different navigation panes. Each navigation pane has different list view that I add depending on the user selection. As far as adding controls on runtime concerns, I dont have any problem with it. However, when I add the control at runtime and then populate the list view data, it displays a grey box until the control is filled and then docked top in the pannel. What I am thinking is to add controls on runtime using the main thread and populate the data with another thread. Will it be ok?

Thanks for the help, Nauman.
0
 
LVL 1

Assisted Solution

by:CrazyIvan007
CrazyIvan007 earned 1000 total points
ID: 11943583
This will work too! The problem is the populating of the ListView which needs some time, if you let them run in a Thread the UI can build up the other Controls without waiting until the ListView is populatet.



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question