DataGridView滚动条损坏/错误 [英] DataGridView scrollbar corruption/bug

查看:77
本文介绍了DataGridView滚动条损坏/错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到DataGridView控件的奇怪行为,请参阅下面的场景描述。我认为这是一个错误,我看到很多其他人遇到了问题,但尚未发布修复程序。我似乎也无法找到问题的合理解释或解决方法。

场景:DataGridView在计时器上刷新。如果在使用鼠标单击并按住滚动条箭头(向下或向右箭头)时网格刷新,则滚动条"已损坏"。腐败我的意思是:


  1. 滚动条箭头消失,滚动条不再适用于该方向(垂直或水平)。
  2. 单击箭头所在的区域并拖动可以调整网格大小。
  3. 双击箭头用于最大化表单内网格的区域,就好像它是MDI子窗口一样。
  4. 一旦最大化,就无法将数据网格恢复到原始大小。

我知道问题只会发生,因为滚动条被隐藏并重新显示在刷新过程中,有效地从我的鼠标点击/保持下拉出地毯。我知道这是因为如果列是静态的并且只清除/添加了行,则水平滚动条不会发生问题。

我强烈认为这是一个错误,因为问题确实是 not 当我单击并拖动滚动条本身时,只有当我单击并按住滚动条箭头时才会发生。实际上,看起来滚动条句柄是专门编码以避免这个问题;如果我在刷新期间单击并拖动滚动条,我的鼠标单击将被"取消",之后不再拖动滚动条。

行为很容易重现,如下所示:


  1. 创建一个测试C#Windows应用程序(下面的说明和代码)。
  2. 运行该应用程序。单击并按住垂直滚动条上的向下箭头。 (这也适用于水平滚动条上的右箭头。)
  3. 当计时器事件重新加载网格时,scollbar将会中断。




  • 创建一个名为DataGridTest的新C#Windows应用程序。
  • 增加Form1的大小,任何东西都应该工作(我使用800x600)。

  • 添加一个DataGridView控件,使其小于Form1的大小(我使用400x300) 。
  • 在Form1类中定义一个私有定时器变量:

private System.Windows.Forms。 Timer m_RefreshTimer;

解决方案

作为解决方法,如何关于如果没有按下鼠标按钮只更新?




Code Snippet

I am seeing odd behavior with a DataGridView control, see the scenario description below. I think it is a bug, and I see that many other people have had the problem but a fix has not been issued.  I also cannot seem to find a reasonable explanation of the problem or a workaround.

Scenario:  DataGridView refreshes on a timer.  If the grid refreshes while scrollbar arrow (down or right arrow) is clicked and held with the mouse, the scrollbar is 'corrupted'.  By corrupt I mean that:

  1. The scrollbar arrow disappears, and the scrollbar no longer works for that direction (vertical or horizontal).
  2. Clicking the area where the arrow used to be and dragging allows the grid to be resized.
  3. Double-clicking the area where the arrow used to be maximizes the grid within the form as if it were an MDI child window.
  4. Once maximized, there is no way to restore the data grid to its original size.

I know that the problem only happens because the scrollbar(s) are being hidden and redisplayed during the refresh, effectively pulling the rug out from under my mouse click/hold.  I know this because the problem does not happen with the horizontal scrollbar if the columns are static and only the rows are cleared/added.

I strongly feel that this is a bug because the problem does not happen when I click and drag the scrollbar itself, only when I click and hold the scrollbar arrow.  In fact, it looks like the scrollbar handle is specifically coded to avoid this problem; if I click and drag the scrollbar during a refresh, my mouse click is 'cancelled' and is no longer dragging the scrollbar afterward.

The behavior is easily reproducable as follows:

  1. Create a test C# Windows Application (instructions and code below).
  2. Run the application.  Click and hold the down arrow on the vertical scrollbar. (This also works for the right arrow on the horizontal scrollbar).
  3. When the timer event reloads the grid, the scollbar will break.


  • Create a new  C# Windows Application named DataGridTest.
  • Increase the size of Form1, anything should work (I used 800x600).
  • Add a DataGridView control, make it smaller than the size of Form1 (I used 400x300).
  • Define a private timer variable within the Form1 class:

private System.Windows.Forms.Timer m_RefreshTimer;

解决方案

As a workaround, how about only updating if the mouse button is not depressed?

 

Code Snippet


这篇关于DataGridView滚动条损坏/错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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