DataGridView使用虚拟模式实时显示数据表 [英] DataGridView live display of datatable using virtual mode

查看:507
本文介绍了DataGridView使用虚拟模式实时显示数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView,它将显示数据库中的记录(日志条目)。一次可以存在的记录量非常大。我想使用DataGridView的虚拟模式功能来显示数据页面,并最大程度地减少在给定时间必须通过网络传输的数据量。

I have a DataGridView that will display records (log entries) from a database. The amount of records that can exist at a time is very large. I would like to use the virtual mode feature of the DataGridView to display a page of data, and to minimize the amount of data that has to be transferred across a network at a given time.

无法进行数据轮询。一次将有多个客户端运行,所有客户端都在同一网络上并查看记录。如果它们都轮询数据,则网络将运行非常缓慢。

Polling for data is out of the question. There will be several clients running at a time, all of which are on the same network and viewing the records. If they all poll for data, the network will run very slowly.

数据对用户是只读的;他们将无法对其进行任何编辑,只能对其进行查看。我需要知道数据库中何时发生更新,并且需要使用虚拟模式相应地使用这些更新来更新屏幕。如果用户正在查看的数据页面包含已更改的数据,则他/她将在该页面上看到这些更新。如果对数据库中的数据进行了更新,而不是对用户正在查看的数据进行了更新,则用户屏幕上的更改实际上并没有太大变化(如果添加或删除了记录,则可能只是滚动条)。

The data is read-only to the user; they won't be able to edit any of it, just view it. I need to know when updates occur in the database, and I need to update the screen with those updates accordingly using virtual mode. If a page of data a user is viewing contains data that has change, he/she will see those updates on that page. If updates were made to data in the database, but not in the data the user is viewing, then not much really changes on the user screen (Maybe just the scroll bar if records were added or removed).

我当前的方法是将SQL Server更改跟踪与同步框架一起使用。每个客户端都有一个本地SQL Server CE实例和数据库文件,这些实例与主数据库服务器保持同步。我使用同步事件中的信息来查看是否对主数据库进行了任何更改并将其同步到客户端。我需要在这里使用DataGridView虚拟模式,因为我无法一次将数千条记录加载到DataGridView中,否则内存使用量将激增。

My current approach is using SQL server change tracking with the sync framework. Each client has a local SQL Server CE instance and database file that is kept in sync with the main database server. I use the information from the synchronization event to see if any changes were made to the main database and were sync'ed to the client. I need to use the DataGridView virtual mode here because I can't have thousands of records loaded into the DataGridView at once, otherwise memory usage goes through the roof.

目前的挑战是,知道如何使用虚拟模式通过允许用户在记录中上下滚动来为用户提供无缝的体验,并实时更新记录而不会不当地干扰用户。以前有没有人处理过这个问题,如果可以,我在哪里可以看到他们是如何做到的?我已经阅读了有关虚拟模式的一些MSDN文档和示例。到目前为止,我还没有在他们的网站上找到文档和/或示例来说明如何完成我要完成的工作。

The main challenge right now is knowing how to use virtual mode to provide a seamless experience to the user by allowing them to scroll up and down through the records, and also have records update on the fly without interfering with the user inappropriately. Has anybody dealt with this issue before, and if so, where I can see how they did it? I've gone through some of the MSDN documentation and examples on virtual mode. So far, I haven't found documentation and/or examples on their site that explains how to do what I am trying to accomplish.

推荐答案

添加以下内容以启动表单

Add following to form startup

 dataGridView1.CellValueNeeded +=new DataGridViewCellValueEventHandler( dataGridView1_CellValueNeeded );  
    dataGridView1.VirtualMode = true;

在接收更新的位置使用以下代码

Use the following code where u receive the update

dataGridView1.RowCount = (int)rowscount.TotalCount;

添加以下功能:

private void dataGridView1_CellValueNeeded( object sender, DataGridViewCellValueEventArgs e )
            {
                _cache.LoadPage( e.RowIndex );    
                int rowIndex = e.RowIndex % PageSize;    
                e.Value = datatable.rows[rowIndex][e.ColumnIndex];
            }

这篇关于DataGridView使用虚拟模式实时显示数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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