How to Stop Listbox Flicker in VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

I see some persons mentioning that their .NET Listbox is flickering when they add alot of items. There is a easy work around that will stop that from happening. The ‘Listbox.BeginUpdate’ and ‘Listbox.EndUpdate’ subs should do the trick.  All you have to do is call the Listbox.BeginUpdate sub before you start adding items, and then call the Listbox.EndUpdate sub after you’ve added your items. BeginUpdate suspends the Listbox control from drawing/redrawing. So while you are adding items, calling this sub before you begin adding items will keep the listbox from showing the items until you call the EndUpdate sub. And likewise calling the EndUpdate sub will then allow the Listbox to redraw showing the items that you’ve added to it. Below is a simple example…


 

Listbox1.BeginUpdate()

Listbox1.Items.Add(“All of My Items))

Listbox1.EndUpdate

Thats all there is to it 🙂

Jason H

2 thoughts on “How to Stop Listbox Flicker in VB.NET

  1. kiran

    ya it is good….
    but i want to know one answer…..
    the question is

    We need a small VB.net tray application (running similar to Google Desktop, or Norton, or something like that….where when you shrink the application it goes down under the far right taskbar).
    We need it to have a simple grid, line-by-line and it will pull from an already created view in SQL 2005. 99.99999% of the work will be on the pulling of the data so it pulls it almost instantly. And, when a row is updated in the table on SQL server…the grid must be updated in the app.
    Platform:
    Vb.NET
    Visual Basic .NET
    .aspx
    Visual Studio 2005
    Microsoft SQL Server 2005

    Reply
  2. Jason H

    Hi, to add custom menu items, controls (textbox for example) and such to the to the TaskBar Caption area will require Interoping with Windows API’s. Below are a couple websites to get you started. You’ve got me somewhat curious on doing this so I am going to see about creating a example app to do this in the future. But anyways, below are a couple links to help you in the right direction.

    ‘This site shows how to add your own custom menu items to the right click menu.

    http://www.dotnetrix.co.uk/menus.html

    ‘This site shows how to add buttons to your apps taskbar caption area. IT is in C++ so you will have to convert it over to Visual Basic.

    http://www.catch22.net/tuts/titlebar.asp

    Those links should help you to get going. I will try to learn more on this subject and maybe get a example done in the coming weeks.

    Hope this helps 🙂

    Jason

    Reply

Leave a Reply

Your email address will not be published.