Solved

Screen flickering while adding items at runtime..

Posted on 2004-08-30
10
279 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 250 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 250 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

Technology Partners: 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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