2023年2月4日 星期六

DataGridView setting DataSource is too slow

I'VE FOUND THE SOLUTION!!!!

The main reason that databinding a datatable to a grid is so slow is because the drawing of the columnnames takes alot time. The simple line of code:
gridHeader.ColumnHeadersVisible = false;

Speeds up the databinding process from 180-300 ms to 4 ms!!!

Now this might not be a good solution for you because the tablecolumns are quite important for the showing of data, but for me it's not a problem as I already create some custom controls that I place over the column names. So by disabling the column names, my own column-name-controls remain present and give the user insight in which column is what. 


DataGrid.ColumnHeadersVisible = False
DataGrid.DataSource = MyDataTable
DataGrid.ColumnHeadersVisible = True


資料來源:https://www.codeproject.com/Questions/175013/DataGridView-setting-DataSource-is-too-slow