直接行数设置,数量相隔很大的话程序会卡死,
RowHeadersWidthSizeMode属性和ColumnHeadersHeightSizeMode属性,非常影响,DataGridView的显示性能,DataGridView的数据绑定应该是迭代的,如果你把DataGridViewRowHeadersWidthSizeMode设置了AuToSize类型的属性,那么每设置一行就要进行一次对HeaderWidth的调整,那么对于N行的表就将进行N!次操作,再加上列的情况,这种性能损失将是巨大的.
dgvData_Signal.RowCount = dtSignal.Rows.Count;
在Designer.cs 代码中设置
If you have a huge amount of rows, like 10,000 and more, to avoid performance leaks - do the following before data binding:
dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
// or even better, use .DisableResizing. Most time consuming enum is DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
// set it to false if not needed
dataGridView1.RowHeadersVisible = false;
//After the data is bound, you may re-enable it.
刷新前Clear:
dgvData_Signal.Rows.Clear();
dgvData_Signal.RowCount = dtSignal.Rows.Count;