Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


TabControl takes a while to display controls

Posted on 2004-10-27
Medium Priority
Last Modified: 2010-04-23

I have a TabControl with 4 TabPages.
Each of them has a listbox in it.... which i populate using data from a database.
Sometimes each listbox can contain a few thousand ListItems.

I am populating all my listboxes at the same time when the form loads.

The problem I'm facing is as below:

After the listobx populating process is over,
if I click on the Second TAB(which contains a listbox with about 15000+ items in it), it a takes a while for the tab to display the controls in it.

BUT now if i move to another tab and then Back to the second Tab, the controls are displayed instantly.

In other words, only when i click a Tab (that has a listbox with many items in it) for the first time, it takes times to display the controls.

Now if I hide the form and then show the form again, I get the same problem. The first time i click on tabs that have a number of items in its listbox take a while to display. Subsequent clicks on that same Tabs, displays the controls in it instantly.

Please, anyone could you let me know how I can get rid of this problem.


Question by:sukhdev
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
LVL 25

Expert Comment

ID: 12419276
Hi Sukhdev,

The reason you get this is because of the JIT compiler it will only "build" the listbox the first time you show it, that is why you only get it the first time.

I have no idea how you could speed it up, maybe a suspendlayout and resumelayout when you show the tab.

But maybe somebody else has an idea, so I'm listening to this thread aswell and maybe learn something too.



Expert Comment

ID: 12419940

if the listbox has that many items in it, and it is taking a long time to fill it to the detriment of the main application, then fill the listbox in a seperate thread, and you will probably want to call the .add item of the listbox in method that delegates control back to the main thread?

not sure if that is the sort of thing you mean?


Expert Comment

ID: 12422830
I have experience the same problem, but only when in development mode (DEBUG)...as soon as I compile and deploy the Application in RELEASE mode...everything is snippity-snappy fast.
Industry Leaders: 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!


Author Comment

ID: 12431027
Hi again,

Actually the adding part is not a problem. I had done put the adding of items in a separate thread since the beginning.
The problem I was facing is after the adding process.

Anyway, after a lot of tries here's what I did to speed the process up. I guess it might come handy for someone:

Scenario I - Loading the form for the first time
1 Before speeding it up (this was the original - problem existed)

In the Form Load event,  i did the following in the following order
    - Detected using a boolean variable if the form was loaded for the first time, if yes do the following
    - I create a new thread
    - Started it. In this thread I added the item to all the listboxes in the tabs
    - Code shown below

    Private Sub frmSelection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If bolFirstTimeLoading Then
            SelectionThread = New Thread(AddressOf addItemsToListBox)
        End If
    End Sub

2. After speeding it up (after modifying the code and speeding the display of controls in the tab)

In the Form Load event, i modified the code slightly, which made part of the problem go away.
      - Detected using a boolean variable if the form was loaded for the first time, if yes do the following
      - Selected each Tab one by one, before adding items (done so that the tab can draw the controls)
      - Created a thread
      - Started the thread
      - Code shown below

Private Sub frmSelection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If bolFirstTimeLoading Then
            'The following four lines of code is necessary
            'These lines will make the tab display the controls within it instantly, in case of large amount of listitems
            'Without these, it controls in the TAB takes a while to display
            'Note: SelectedIndex =0 should be the last line. Because we want it to be displayed when the form shows
            TabSelection.SelectedIndex = 1
            TabSelection.SelectedIndex = 2
            TabSelection.SelectedIndex = 3
            TabSelection.SelectedIndex = 0
            SelectionThread = New Thread(AddressOf addItemsToListBox)
        End If
    End Sub

This worked just as I wanted to. Now even after doubling the items in the listbox, On clicking the Tabs the controls were shown instantly.

On closing the form, I simply made it invisible to the user, by doing

The hiding of form was done to save time, from re-adding items into the listbox
However, when showing (i.e. unhiding) the form now... the problem still existed.

Scenario II - Unhiding the same form
Not yet solved.

problem: If i click on Tab 2 (after unhiding the form) then it takes a while to display the controls.
However this happens only when i click the tab 2 for the first time.
Any other clicks on Tab 2, displays the controls in it instantly.

I've been able to solve the Scenario I, please could anybody here help me solve Scenario II also.
Maybe I've missed out something.


Author Comment

ID: 12502489
Hi all,

I think the solution i found out myself, solves the problem. so I think I'll close the question now.

Thanks anyway.

Accepted Solution

modulo earned 0 total points
ID: 12534319
Closed, 75 points refunded.

Community Support Moderator
Experts Exchange

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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