【问题标题】:refresh datagridview only if contents change仅在内容更改时刷新 datagridview
【发布时间】:2017-07-14 23:48:14
【问题描述】:

我有一些绑定到数据源的 Datagridview。该数据取自数据库,需要不断更新。 (我每秒刷新一次 Datagridview) 这种不断的刷新会导致滚动、选择等一些明显的问题。数据变化不是那么频繁,大约一分钟两次,但是当它变化时,我需要快速更新Datagrid,从而频繁刷新。

有没有办法快速验证(例如通过使用哈希函数等)来查看数据源的内容是否已更改?我想避免比较每个单元格/行,因为对于我所有的 datagridviews 来说,软件可能需要做太多的工作。有没有更好的办法?

谢谢

【问题讨论】:

    标签: datagridview compare refresh datasource


    【解决方案1】:
    DataSet dsBindedToDataGridView = new DataSet(); // Get data from DB & Bind this to DataGridView and persist it.
    DataSet dsRetrivedOnRefresh = new DataSet(); //Add code to fetch data from DB
    
     var result = dsBindedToDataGridView.Tables[0].AsEnumerable().Except(dsRetrivedOnRefresh.Tables[0].AsEnumerable(),DataRowComparer.Default);
    //Now if result has got any value then data has changed and you need to refresh the data else ignore
    

    【讨论】:

    • 似乎不起作用..我使用两个数据表而不是数据集,但做同样的事情。绑定的数据表为空,刷新时检索只有一行。 result.any 返回 false。
    • 绑定DataGridView后你的数据表没有持久化吗?
    • 这是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多