Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Virtual mode: a VERY SLOW performance

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Virtual mode: a VERY SLOW performance
Link Posted: 07-Mar-2007 05:31
Hi

I need virtual grid to make data fly  when you have thousands of records. One single level (no nested records).

I did a very simple example with 1 column.

After you fill it with 100000 records and try to scroll down in a large portion (drag scroll bar marker to say 30% of whole length) - it takes about 6 sec to finish the operation.

I tried 100000 records on your Virtual Grid sample - it works very fast (no delays at all).

I cant find what is wrong with my code.

Help will be really appreciated!!

Find my code below
Link Posted: 07-Mar-2007 05:34
a. Form

        private void InitializeComponent()
        {
            this.flyGrid1 = new NineRays.Windows.Forms.FlyGrid();
            this.column1 = new NineRays.Windows.Forms.Grids.Column();
            this.button1 = new System.Windows.Forms.Button();
            this.txt = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.flyGrid1)).BeginInit();
            this.SuspendLayout();
            //
            // flyGrid1
            //
            //
            //
            //
            this.flyGrid1.Columns.Items.AddRange(new NineRays.Windows.Forms.Grids.Column[] {
            this.column1});
            this.flyGrid1.Location = new System.Drawing.Point(13, 13);
            this.flyGrid1.Name = \"flyGrid1\";
            this.flyGrid1.Opacity = 1;
            this.flyGrid1.Options = ((NineRays.Windows.Forms.Grids.GridOptions)((NineRays.Windows.Forms.Grids.GridOptions.ReadOnly | NineRays.Windows.Forms.Grids.GridOptions.Default)));
            this.flyGrid1.Size = new System.Drawing.Size(267, 241);
            this.flyGrid1.TabIndex = 0;
            this.flyGrid1.Text = \"flyGrid1\";
            //
            // column1
            //
            this.column1.AllowFiltering = true;
            this.column1.Caption = \"Column 1\";
            this.column1.ImageKey = null;
            this.column1.State = NineRays.Windows.Forms.Grids.ColumnState.DropDownBtnUp;
            this.column1.Width = 150;
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(575, 281);
            this.button1.Name = \"button1\";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = \"button1\";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // txt
            //
            this.txt.Location = new System.Drawing.Point(469, 283);
            this.txt.Name = \"txt\";
            this.txt.Size = new System.Drawing.Size(100, 20);
            this.txt.TabIndex = 2;
            this.txt.Text = \"10\";
            //
            // Form1
            //
            this.AcceptButton = this.button1;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(662, 316);
            this.Controls.Add(this.txt);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.flyGrid1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Name = \"Form1\";
            this.Text = \"Form1\";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.flyGrid1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private NineRays.Windows.Forms.FlyGrid flyGrid1;
        private NineRays.Windows.Forms.Grids.Column column1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox txt;
Link Posted: 07-Mar-2007 05:34
b. main

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            flyGrid1.VirtualMode_GetCount += new GetCountHandler(flyGrid1_VirtualMode_GetCount);
            flyGrid1.VirtualMode_GetNodeCellValue += new GetCellValueHandler(flyGrid1_VirtualMode_GetNodeCellValue);
            flyGrid1.Rows.VirtualMode = true;
        }

        object flyGrid1_VirtualMode_GetNodeCellValue(object sender, NodeBase node, int index)
        {
            return 99;
        }

        int flyGrid1_VirtualMode_GetCount(NodeBase sender)
        {
            return Convert.ToInt32(txt.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            flyGrid1.Rows.Reset();
            flyGrid1.Rows.RootNode = null;
            flyGrid1.Invalidate();
        }
    }
Link Posted: 07-Mar-2007 06:08
I found the answer!

actually virtual functionality has to be tweaked mate! I found that a) GetCount being called all the time when you scroll. But in my understanding - as long as grid not being repainted all the way long (you dont see data while you drag scroll marker) - I believe there is no point to call GetCount for every record. I believe that records must be repainted (and relevant data must be retrieved for) for visible records only!
b) it seems GetCount being called twice for every record. I dont understand what could be the reason to do so.

How I get these results - I counted GetCount hits dragged scroll marker whole way from top to bottom and then from bottom to top.

Stats are: after initial changing number of records to 100,000 it had 100307 hits or so; after dragging full way down then stop then dragging whole way up and stop - GetCount showed 520000-ish hits.

Wow... not very effective.

Please fix this problem. Your flygrid gonna fly as a rocket after that!!

Please tell me if I can be more at help and we can get through this issue in details.
Link Posted: 07-Mar-2007 06:09
Yeah forget to tell what was wrong with code

Here


        int counter = 0;
        int flyGrid1_VirtualMode_GetCount(NodeBase sender)
        {
            //return Convert.ToInt32(txt.Text); <----- !~!~!~!~!~!~BAD BAD CODE~!~!~!~!~!~!
            return counter;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            counter = Convert.ToInt32(txt.Text);

            flyGrid1.Rows.Reset();
            flyGrid1.Invalidate();
        }

Link Posted: 07-Mar-2007 06:28
Ok. Here is another update.

If you set row count to 100,000 and scroll from top to bottom. then you have GetCount hitted about 200000 times. But GetNodeCellValue get hit very modes number of times. Which reflects its natural value. If you scroll it very fast it get hit less than if you scroll it slow.

Which brings me to conclusion that problem is with GetCount only.

Here are my questions:

1. can GetCount be optimised?

2. can you implement GetNodeValue instead (for a case when you use virtual grid mostly in full length wherefore whole row is visible. in such a case I believe you can increase efficiency not picking every cell but sending a whole data row into grid to display)

Thank you
Link Posted: 08-Mar-2007 09:59
1. can GetCount be optimised?

Yes, you can make your own nodes collecion - use your own RootNode that will dynamically provide nodes count and nodes instances.
You can use virtual datasource or another ways to provide functionality that meets your needs - for example you can don't use Virtual mode and manually referesh count of nodes, but use self-fetched nodes - node that provide data to display by itself.
2. can you implement GetNodeValue instead (for a case when you use virtual grid mostly in full length wherefore whole row is visible. in such a case I believe you can increase efficiency not picking every cell but sending a whole data row into grid to display)

You can create your own node instance that will provide node value - as I've understood this would better. You can override NodeBase.GetCellValue/SetCellValue methods to implement this(virtual mode like) functionality.