【问题标题】:My DataGridView blinks when refreshing刷新时我的 DataGridView 闪烁
【发布时间】:2013-10-14 10:45:16
【问题描述】:

如果我在 datagridview 中刷新一些数据,我会失去对选定单元格的关注并且随机文本闪烁

为什么会这样?在其他应用中我没有看到这个问题,所以我可以解决这个问题,但是如何解决?

我通过这段代码刷新数据:

SBind.DataSource = DTable; // SBind is binded my grid.DataSource = SBind
SBind.ResetBindings(false);

【问题讨论】:

    标签: c# winforms datagridview


    【解决方案1】:

    试试这个:

    SBind.SuspendLayout();
    SBind.DataSource = DTable;
    SBind.ResetBindings(false);
    SBind.ResumeLayout(true);
    

    您也可以尝试启用网格的DoubleBuffered,如下所示:

    typeof(Control).GetProperty("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance)
                   .SetValue(SBind, true, null);
    

    【讨论】:

    • @Greag.Deay 只需保存一些标识(以识别所选行),然后在刷新网格后,找到该行并将其标记为选中。无论如何,我不确定您为什么需要以这种方式刷新网格。
    【解决方案2】:

    这也有帮助:

    dataGridView1.DoubleBuffered(true);
    

    https://msdn.microsoft.com/en-us/library/3t7htc9c(v=vs.110).aspx

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 2012-02-06
      • 1970-01-01
      • 2014-01-30
      相关资源
      最近更新 更多