水平滚动时如何防止DataGridView闪烁? [英] How to prevent DataGridView from flickering when scrolling horizontally?

查看:19
本文介绍了水平滚动时如何防止DataGridView闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 窗体 C#.

I am using windows forms C#.

如屏幕截图所示,我有一个表单,其中包含一个用户控件、一个选项卡控件和一个 DataGridView(30 行 17 列).我从 SQL Server 读取数据以填充 DataGrdiView.

As shown in the screen shot, I have a Form which has a user control, a tab control and a DataGridView (30 rows and 17 columns). I read data from SQL Server to fill the DataGrdiView.

问题:

当我水平滚动时,DataGridView 会闪烁很多.然而,垂直滚动效果很好,没有闪烁.

When I scroll horizontally the DataGridView flickers a lot. However scrolling vertically works perfect with no flickering.

我看了这里这里此处此处 但没有一个与我的问题有关.

I had a look here, here, here and here but none of them related to my issue.

任何人都知道防止 DataGridView 在水平滚动时闪烁的任何解决方案.

Anyone knows any solution to prevent DataGridView from flickering when scrolling horizontally.

推荐答案

使用这个类

public static class ExtensionMethods
{
   public static void DoubleBuffered(this DataGridView dgv, bool setting)
   {
      Type dgvType = dgv.GetType();
      PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
      pi.SetValue(dgv, setting, null);
   }
}

并输入此代码.

this.dataGridView1.DoubleBuffered(true);

享受.

这篇关于水平滚动时如何防止DataGridView闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆