Datagridviews hang application.

Posted on 2011-05-12
Last Modified: 2013-11-07
Ok.  So here's the pickle.

When my application is executed in debug mode, everything works as I would expect.  However, when executing it outside the IDE, I get a couple of weird behaviors that I think are related.  
Here's the set up for the datagridviews in question.  

They both use their own bindingsource controls which point to their own tables in the same dataset.  
datagridview1 (dgv1) underlying table is populated using table.copy form another table.  It gets roughly 2000 rows.
datagridview2 (dgv2) underlying table is then populated from within a backgroundworker adding rows via .add(newrow).  It gets roughly 17000 rows.
Both of these dgv's are located on a tabpage that isn't visible until the backgroundworker is complete.  

Note:  I remove and add the tabpages of the tabcontrol based on a combobox selection.  

Behavior 1)  If I close the application (the backgroundworker process has ended), without moving to their tabpage, the application hangs for several minutes when trying to dispose either of them.
Behavior 2)  If I switch to their tabpage the first time, the application hangs when adding the tabpage to the tabcontrol for several minutes before the tabpage displays any of its controls.  But if I then close the application, it closes immediately without hanging during their dispose.

When troubleshooting Behavior 1, I can successfully dispose the datatable, dataset and binding source prior trying to dispose the dgv's, but the dgv's will still hang.  Also, if I try to set the datasource to nothing or to do a dgv.columns.clear it will hang.  dgv.rows.clear is successful.

This makes me think it has something to do with the columns.  I've tried disabling the only size property enabled, the AutoSizeColumnsMode, which is set to fill, but the problem persists.  

I thought it might be thread related, but all of my threads have completed and returned to the main control before I try any of these steps.  I'm at a loss how to proceed.
Question by:rogerard
    LVL 7

    Author Comment

    Another note for Behavior 2:  Once the dgv's are displayed the vertical scroll bars are non-functional and their gdi is corrupt.  I'm still able to cycle through the values using the mousescroll or arrows on the keyboard.
    LVL 7

    Accepted Solution

    Ok.  I figured it out.  I'm sure it's thread related, but definitely has to do with datatable population.  I set the dgv's datasource to nothing prior to launching the routines to populate their data, then reassigned their datasources to their bindingsource controls once the datatables were populated.  Now there are no hangs.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now