optimize updates to DataTable bound to DataGridView

后端 未结 7 1209
执念已碎
执念已碎 2021-02-14 19:27

I have a Form in my application that displays some data. When I first show the Form, I load some data into a DataTable then bind the DataTable to a DataGridView. I also start an

相关标签:
7条回答
  • 2021-02-14 20:11

    I ran into a similar problem. Here's a solution that is even simpler (if less elegant).

    I found that this:

    dataGridView.DataSource = null;
    dataTable.BeginLoadData();
    foreach(DataRow row in dataTable.Rows){
        //modify row
    }
    dataTable.EndLoadData();
    dataGridView.DataSource = dataTable;
    

    ...is way faster than this:

    dataTable.BeginLoadData();
    foreach(DataRow row in dataTable.Rows){
        //modify row
    }
    dataTable.EndLoadData();
    

    Cheers--DC

    0 讨论(0)
提交回复
热议问题