问题描述:当数据量过多,但是又需全部展示出来时;拖动dataGridView滚动条时数据逐条更新,加载缓慢;
解决方案:利用System.Reflection缓冲刷新
代码实现:
/// <summary> /// 缓冲帮助类 /// </summary> public class Buffered { /// <summary> /// 用于解决dataGridView数据更新问题 /// 利用反射机制修改控件的的Protected的DoubleBuffered属性 /// </summary> /// <param name="dgv">DataGridView控件</param> /// <param name="setting">是否开启</param> public static void DoubleBuffered(System.Windows.Forms.DataGridView dgv, bool setting) { dgv.GetType() .GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .SetValue(dgv, setting, null); } }