Loading a DataTable Slow when bound to a DataGridView.Datasource

I was looking for everything, and I can’t figure it out. I am working on a Winforms user interface that pulls out large volumes of rows that I need to display in a DataGridView. I've already read all about row limit and swap, and there is absolutely no good way for me to do this. I mainly work on the TargetDataViewer control of the Advanced Event Manager for SQL Server 2008, which I wrote in Codeplex.

http://extendedeventmanager.codeplex.com/

I will limit myself to what I can do based on a specific goal and how it presents the data. What I'm trying to do is stream the data that was read from the target into the DataGridView, just like Profiler or SQL Server Management Studio display data as it arrives. I rewrote a lot of code and got BackgroundWorker data to extract the data and process it in a DataTable. If I do not set DataGridView.DataSource = DataTable, I can load 300K + rows of data into a DataTable in a few minutes, it really works fast. As soon as I add a DataTable to a DataSource, it will almost stop (instead of just a few minutes, the same 300K rows can take 1/2 hour).

I know that the problem is not in my processing code, it is specific for binding to a DataGridView.DataSource, and I have a time code to prove it. I can’t figure out how to get around this. For performance, I may be late to associate the control with a DataTable after loading the data, but this is a very crappy user interface. I see that many people complain about the impact of the performance of a DataGridView when loading data, so this might just be a limitation I'm stuck with? Any ideas?

+3
source share
1 answer

, , unbound DataTable DataReader: <<22 > , DataReader Rows. , , DataGridView .

DataTable, DataGridView ? . , , , . 300 000 , 300 000 .

, ? :

private void PopulateDataTable()
{
    int rowCount = 10000;

    bindingSource1.RaiseListChangedEvents = false;
    for (int i = 0; i < rowCount; i++)
    {
        DataRow r = DT.NewRow();
        for (int j = 0; j < ColumnCount; j++)
        {
            r[j] = "Column" + (j + 1);
        }
        DT.Rows.Add(r);

        if (i % 500 == 0)
        {
            bindingSource1.RaiseListChangedEvents = true;
            bindingSource1.ResetBindings(false);
            Application.DoEvents();
            bindingSource1.RaiseListChangedEvents = false;
        }
    }
    bindingSource1.RaiseListChangedEvents = true
}

ResetBindings, . , DataGridViewRow, . , 10-, 10000 DataTable, DataGridView, 2900 . , 155 . reset 500 , 840 .

, 300 000 , reset 500 ; , , 500 , , . , Application.DoEvents , .

Edit

Application.DoEvents; , .

, BackgroundWorker ProgressChanged, DoWork. , DataGridView, .

+12

Source: https://habr.com/ru/post/1712898/


All Articles