DataGridView中,虚拟模式和"滞后" [英] DataGridView, Virtual Mode and "lags"

查看:177
本文介绍了DataGridView中,虚拟模式和"滞后"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

private void dataGridView4_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            Records recordsTmp  = null;
            recordsTmp = (Records)this.ArrayOfRecords[e.RowIndex]; //ArrayList with string[] objects inside


            switch (dataGridView4.Columns[e.ColumnIndex].HeaderText)
            {
                case "#":
                    e.Value = recordsTmp.nr;
                    break;
                case "ip":
                    e.Value = recordsTmp.Ip;
                    break;
                case "long":
                    e.Value = recordsTmp.Long;
                    break;
                case "3":
                    e.Value = recordsTmp.type;
                    break;
                case "4":
                    e.Value = recordsTmp.time;
                    break;
            }




  • ArrayOfRecords 与每秒10-100新的的String [] 对象更新。

  • VirtualMode 设置为true。

  • 的SelectionMode 设置为 FullRowSelect

  • 的dataGridView 是只读的。

    • ArrayOfRecords is updated with 10-100 new string[] objects per second.
    • VirtualMode is set to true.
    • SelectionMode is set to FullRowSelect.
    • dataGridView is Read-only.
    • 现在还那里有一个进度字幕的风格,让我发现,与可以说5000 +滚动行冻结了表格但我猜它只是线程的问题/ BackgroundWorker的等。

      Now theres also a ProgressBar with Marquee style which shows me that with lets say 5000+ rows scrolling freezes the Form but i guess its just a matter of threading/backgroundworker etc.

      什么让我害怕最重要的是选择。有 8000行并单击最后一个(8000)把我的形式4.2秒选择它。而其如下:

      What scares me most is selection. Having 8000 rows and clicking last one (8000) takes my form 4.2 seconds to select it. And its as follows:

      4000行使得它2.1秒等。如果第八千行被选中minimazing然后最大化需要4.2秒。选择第1行使高兴了。它是不可接受的。 *为什么这么难标记第八千行我表格

      4000 rows makes it 2.1 secs, etc. If 8000th row is selected minimazing and then maximizing takes 4.2 secs. Selecting row 1 "makes it" happy again. Its unacceptable. *Why is it so hard to "mark" 8000th row for my Form?

      VirtualMode的分页完美的作品,但选择,是一种痛苦。

      VirtualMode's pagination works perfectly but selection is a pain.

      也Theres另一个问题/行为:

      Theres also another issue/behaviour:

      为什么 CellValueNeeded 时,即时通讯移动我的鼠标移到行引发事件?他们已经画?那么为什么浪费资源?

      Why CellValueNeeded event is raised when im moving my mouse over the rows? They are already painted? So why is it wasting resources?

      是否有这种选择问题的任何解决方案?或者我有在DataGrid

      Is there any solution for this selection problem? Or i have to limit maximum records in the datagrid

      推荐答案

      来限制最高的记录,你要玩一件事是细胞的自动调整大小,如在GridView将不得不通过所有的细胞,以便找到一个最长的长度。您应该禁用自动调整大小,你应该这样做编程。
      关于你的选择问题:选择导致了很多重绘,我的直觉是,是重绘所有的细胞,因此滞后是成正比的行/细胞计数。

      One thing you want to play with is the autosizing of the cells, as the gridview will have to go through all your cells in order to find the one with the longest length. You should disable autosizing and you should do that programatically. Regarding your selection problem: selecting causes a lot of redraws, my hunch is that is redraws all your cells, therefore the lag is proportional to your row/cell count.

      为了使用虚拟模式需要比VirtualMode设置为true多。这将是有趣的,看看你的dataGridView1_RowsAdded,dataGridView1_CellValuePushed和​​dataGridView1_CellValidating方法,因为它们是延迟的可能是罪魁祸首。

      In order to use Virtual Mode you need more than setting the VirtualMode to true. It would be interesting to see your dataGridView1_RowsAdded, dataGridView1_CellValuePushed and dataGridView1_CellValidating methods, since they are probably the culprit of the delays.

      这篇关于DataGridView中,虚拟模式和"滞后"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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