C# - 我怎么刷新DataGridView中删除行后 [英] C# - how do I refresh DataGridView after removing rows

查看:394
本文介绍了C# - 我怎么刷新DataGridView中删除行后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码,我需要一个反复出现的时间间隔后去除在DataGridView行,所以当定时器超时我调用下面的函数:

In my code I need to remove rows from the DataGridView after a recurring interval, and so I call the following function when a timer expires:

private void removeRows(DataGridView dgv) {

    foreach (DataGridViewRow row in dgv.Rows)
    {
        // if some condition holds
        dgv.Remove(row);                
    }
    dgv.Refresh();

}



我知道行已成功从DataGridView中删除,但他们仍停留在显示器无论出于何种原因。什么我可能是做错了任何提示?

I know the rows are successfully deleted from the DataGridView, though they still remains in the display for whatever reason. Any tips on what I might be doing wrong?

推荐答案

如果您已绑定您的数据网格到一个观察的集合(如果没有,那么你应),那么你将需要实现INotifyCollectionChanged接口,以便监听通知的动态变化,如当项目被添加和删除,或者整个列表被刷新。

If you have bound your datagrid to an Observable Collection (if not then you should) then you will need to implement INotifyCollectionChanged interface so that listeners are notified of dynamic changes, such as when items get added and removed or the whole list is refreshed.

HTH

这篇关于C# - 我怎么刷新DataGridView中删除行后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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