Solved

stop "flashing" while listbox is updated

Posted on 2011-09-11
3
303 Views
Last Modified: 2012-05-12
vs 2008:  I have a form with a listbox control and timer control.  Every 5 seconds the app downloads data from a database to update a listbox with potential new data.  Everytime that happens (new data or not) the form "blinks" while the listbox is re-loaded.  How can I stop this?
0
Comment
Question by:dhenderson12
3 Comments
 
LVL 37

Accepted Solution

by:
Neil Russell earned 250 total points
ID: 36519011
Why reload the listbox if there is no new data?
0
 
LVL 40
ID: 36519082
As pointed to by Neilsr, you should check for new data before updating the ListBox, and update it only when needed. There is surely a way to get a count of the number of items. Just check that the count has changed.

The reason for the blink is that when an item is added to a ListBox (or ComboBox), it automatically becomes the selection. If some event such as the SelectedIndexChanged and SelectedValueChanged event is programmed to to something in the interface, it gets called for every item in the list.

In order to prevent that, you need to stop the event from triggering for a while. Here is the way to do it with the SelectedIndexChanged.
RemoveHandler ListBox1.SelectedIndexChanged, AddressOf ListBox1_SelectedIndexChanged
     'The event won't trigger, you can fill ListBox1 here
     'Once done, reactivate the event with
AddHandler ListBox1.SelectedIndexChanged, AddressOf ListBox1_SelectedIndexChanged

Open in new window

0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
ID: 36519122
Try using BeginUpdate() and EndUpdate():

        ListBox1.BeginUpdate()
        ' ... update data ...
        ListBox1.EndUpdate()

Or Double Buffer the Form.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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