2

I press a button (located on the main form , the MDI Parent) which triggers a BackgroundWorker's RunWorkerAsync method (located on the same MDI Parent form). In this method I set the DataSource of my DataGridView which is located inside one child window owned by my main Mdi Window. Here's the code for the RunWorkerAsync:

        Action d = () => {
        ((DataGridView) data_viewer.gridviewer).SuspendLayout();
        ((DataGridView) data_viewer.gridviewer).DataSource = datatable_copied;
        ((DataGridView) data_viewer.gridviewer).ResumeLayout();
        };
        base.Invoke( d );

The above code populates the grid OK. All data is delivered into the grid. The problem is that I will work with very big tables and while the data is loaded the whole app hangs, including the Mdi Parent window. I wouldn't mind having the DGV hang but for the Main MDI parent and the child window containing the DGV to hang while this whole thing loads is too much. How can I solve this? I want to be able to move the child window containing the DGV without a problem while it loads (or maybe draws) the whole datatable. I thought using a background worker would solve the issue but apparently it doesn't.

kawa
  • 422
  • 4
  • 16

1 Answers1

2

There is no getting around rendering a huge table on a WinForm.

Whether it is async or not, the UI still has to render the entire grid. Pushing it to the background thread just makes the UI more responsive while it is being computed and rendered.

Another approach is to page the data meaningfully, so that you:

  1. Reduce the network traffic
  2. Reduce memory of the WinForm
  3. Speed up the rendering time

Is a user going to need 1,000's or 100,000 rows of data in one hit? Humans can't compute information on that scale - hence reporting aggregates the values.

Have a look at this StackOverflow post relating to paging a DataGridView and see if that helps.

Community
  • 1
  • 1
Dominic Zukiewicz
  • 8,258
  • 8
  • 43
  • 61