This is a migrated thread and some comments may be shown as answers.

Performance issue with custom cells.

27 Answers 438 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 12 Nov 2010, 02:27 PM

Hi!

                I have to use custom cell to display data but I have problem with performance.

                I have 500 rows and when I use my custom cell scrolling is very slow, not fluent.

I made simple test and checked that even if I add only one child control to custom cell, scrolling performance goes down significantly.

Is there any way to improve performance in this kind of scenario?

                This is my source code:

 

 

public class CustomCell : GridDataCellElement
{
    private RadCheckBoxElement _chk;
    public CustomCell(GridViewColumn column, GridRowElement row) : base(column, row)
    {
    }
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        _chk = new RadCheckBoxElement();
        _chk.Margin = new Padding(2, 2, 2, 2);
        _chk.MinSize = new Size(20, 20);
        _chk.Text = string.Empty;
        _chk.ToggleState = ToggleState.Off;
        this.Children.Add(_chk);
    }
    protected override Type ThemeEffectiveType
    { get { return typeof(GridDataCellElement); } }
}

namespace PerformanceIssue
{
    public partial class Form1 : Form
    {
        List<MySample> _list;
        public Form1()
        {
            InitializeComponent();
            _list = this.GenerateList();
        }
  
        private void btnPopulateUnbound_Click(object sender, EventArgs e)
        {
            GridViewDataColumn col = null;
            GridViewRowInfo row = null;
  
            for (int index = 1; index <= 10; index++)
            {
                col = new CustomColumn();
                radGridViewUnbound.Columns.Add(col);
                col.Width = 100;
            }
  
            foreach (MySample item in _list)
            {
                row = radGridViewUnbound.Rows.AddNew();
                row.Cells[0].Value = item.Property1;
                row.Cells[1].Value = item.Property2;
                row.Cells[2].Value = item.Property3;
                row.Cells[3].Value = item.Property4;
                row.Cells[4].Value = item.Property5;
                row.Cells[5].Value = item.Property6;
                row.Cells[6].Value = item.Property7;
                row.Cells[7].Value = item.Property8;
                row.Cells[8].Value = item.Property9;
                row.Cells[9].Value = item.Property10;
            }
            radGridViewUnbound.MultiSelect = true;
        }
  
        private List<MySample> GenerateList()
        {
            List<MySample> list = new List<MySample>();
            MySample item = null;
            for (int index = 0; index < 500; index++)
            {
                item = new MySample()
                {
                    Property1 = string.Format("Row: {0}, Col: {1}", index, 1),
                    Property2 = string.Format("Row: {0}, Col: {1}", index, 2),
                    Property3 = string.Format("Row: {0}, Col: {1}", index, 3),
                    Property4 = string.Format("Row: {0}, Col: {1}", index, 4),
                    Property5 = string.Format("Row: {0}, Col: {1}", index, 5),
                    Property6 = string.Format("Row: {0}, Col: {1}", index, 6),
                    Property7 = string.Format("Row: {0}, Col: {1}", index, 7),
                    Property8 = string.Format("Row: {0}, Col: {1}", index, 8),
                    Property9 = string.Format("Row: {0}, Col: {1}", index, 9),
                    Property10 = string.Format("Row: {0}, Col: {1}", index, 10)
                };
                list.Add(item);
            }
  
            return list;
        }
    }
}

 

               

Regards

27 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 03:20 PM
Hello, 

I have tried out your code and found no performance issues when scrolling. All rows scroll smoothly and without delay. For reference I am using the latest Q3 2010 version that came out yesterday. I'm unable to try your code on an older version. What version are you currently using? 

Regards, 
Richard
0
Raymond
Top achievements
Rank 1
answered on 12 Nov 2010, 03:26 PM
I have 2010 Q2 SP2.
I am downloading Q3, I will check this issue on the newest version.
0
Raymond
Top achievements
Rank 1
answered on 13 Nov 2010, 02:05 PM

I have installed 2010 Q3 and now for unbound mode performance is even worst L

I have WinXP SP3.

Instead of CustomColumn I used standard
GridViewTextBoxColumn and populating grid takes about 40s.

For bound mode it takes about 2s!

 

I have only 500 rows and 10 columns – something is wrong for unbound mode.

Can you take a look once again on my source code? Maybe I do something wrong.

0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 13 Nov 2010, 02:58 PM
Hi,

You mention now about population speed, rather than scroll speed. Is this correct?

Unbound mode will always be slower than bound mode to populate. The fastest way to populate a grid is via a datasource, next it is to use AddRange, then lastly, adding rows one by one.

However, to dramatically speed up adding rows in unbound mode, you should use the new DeferRefresh method of the grid.

See below, I have altered the code (from a button click) that generates your rows.

    private void radButton2_Click_1(object sender, EventArgs e)
    {
        GridViewTextBoxColumn col = null;
        GridViewRowInfo row = null;
        for (int index = 1; index <= 10; index++)
        {
            col = new GridViewTextBoxColumn();
            radGridView1.Columns.Add(col);
            col.Width = 100;
        }
        using (this.radGridView1.DeferRefresh())
        {
        foreach (MySample item in _list)
        {
            row = radGridView1.Rows.AddNew();
            row.Cells[0].Value = item.Property1;
            row.Cells[1].Value = item.Property2;
            row.Cells[2].Value = item.Property3;
            row.Cells[3].Value = item.Property4;
            row.Cells[4].Value = item.Property5;
            row.Cells[5].Value = item.Property6;
            row.Cells[6].Value = item.Property7;
            row.Cells[7].Value = item.Property8;
            row.Cells[8].Value = item.Property9;
            row.Cells[9].Value = item.Property10;
        }
        radGridView1.MultiSelect = true;
        radGridView1.Columns[0].IsPinned = true;            
       }
    }
}


Hope that helps
Richard
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 13 Nov 2010, 07:39 PM
Hello again,

Just try this:
private void btnPopulateUnbound_Click(object sender, EventArgs e)
{
    GridViewDataColumn col = null;
    GridViewRowInfo row = null;
 
    using (radGridView1.DeferRefresh())
    {
        for (int index = 1; index <= 10; index++)
        {
            col = new CustomColumn();
            radGridView1.Columns.Add(col);
            col.Width = 100;
        }
 
        foreach (MySample item in _list)
        {
            row = radGridView1.Rows.AddNew();
            row.Cells[0].Value = item.Property1;
            row.Cells[1].Value = item.Property2;
            row.Cells[2].Value = item.Property3;
            row.Cells[3].Value = item.Property4;
            row.Cells[4].Value = item.Property5;
            row.Cells[5].Value = item.Property6;
            row.Cells[6].Value = item.Property7;
            row.Cells[7].Value = item.Property8;
            row.Cells[8].Value = item.Property9;
            row.Cells[9].Value = item.Property10;
        }
        radGridView1.MultiSelect = true;
    }
}
Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 13 Nov 2010, 07:58 PM
Hi Emanuel,

Isn't this the same thing (but with the DeferRefresh covering slightly more)?

Regards,

Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 13 Nov 2010, 09:45 PM
Hello guys,

The subject of this thread is performance. Using unbound mode will always be slower than bounded mode. But there are a few tricks to make it faster:
- create all the rows (without adding them directly to the grid, store them in a list, or array) and add them using AddRange.
- use BeginUpdate / EndUpdate or the newest one DeferRefresh in order to prevent an update on each action performed

With unbound mode the best you could hope for is getting as close as possible to bound modes.

Also, there is one thing to address here regarding the use of  the custom cell, one of them being overriding IsCompatible:
public override bool IsCompatible(GridViewColumn data, object context)
            {
                if (data.Name == "CustomColumn")
                {
                    return true;
                }
 
                return base.IsCompatible(data, context);
            }

To prevent display glitches when moving columns or other cases in which the grid has to decide what cell type is required.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 13 Nov 2010, 10:37 PM
Hi Raymond,

to sum up..
I've provided you with information on RadgridView.DeferRefresh which enhances the performance of adding rows in unbound mode and also regarding adding rows via AddRange or use of a datasource. Emanuel has also provided information on IsCompatible.

However, are you still experiencing scrolling performance issues as this was the subject of your first thread. If you can confirm this, and if so, under which scroll conditions you are experiencing issues, I'll be happy to help.

All the best
Richard

0
Raymond
Top achievements
Rank 1
answered on 14 Nov 2010, 06:00 PM


Yes I mention now about population speed, rather than scroll speed.

So:

  1. Population speed – I used this new method DeferRefresh and now performance is ok for me – problem solved (even with custom cells). I also used method AddRange.

 

 

2.   Scroll speed – this is still a problem, even if I use standard GridViewTextBoxColumn.

 

Button with arrow down (in scroll control) is being continuously pressed and scrolling process is very slow, I see next row in each about 1 second – CPU is 0% all the time. Scrolling in System.Windows.Forms.DataGridView is much faster – CPU is also 0%.

Because during scrolling (pressed button with arrow down in scroll control) CPU is 0% I think I could be faster. Is there any way to improve speed during scrolling (with standard GridViewTextBoxColumn)?

 

The same problem is when I select last visible row and I keep pressed keyboard button arrow down (continuously) – but additionally in this case after couple seconds CPU jumps to 50%. In System.Windows.Forms.DataGridView it works fine.

 

Do you have any ideas?



btw: Where can I read about new members of classes in new relaeses of Telerik controls?


 Regards

 

 

0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 06:31 PM
Hello Raymond,

You can read about What's new in Q3 here
The release notes for Q3 are here
this link contains an overview of RadGridView for Q3

I have noticed that the RadGridViews in the Demo applications seem to have the same issue with scrolling performance past the visible rows, and again as per your other thread, the workaround to this seems to be refreshing the RadGridView on selection changed.

private void radGridView1_SelectionChanged(object sender, EventArgs e)
{
    if (this.radGridView1.SelectedRows.Count > 0)
    {
        this.radGridView1.Refresh();
    }
 }

I hope this heps, but just let me know if you need more information.

All the best
Richard
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 07:50 PM
Hi guys,

Just to let you know, i'm also facing this slow scrolling issue.
It's like there's a 1s lag between the mouse wheel scroll and the grid scroll.. very annoying.

(using Q2 and now Q3)

Rafael
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 08:01 PM
Hello Rafael,

Have you tried the workaround above? I.e
private void radGridView1_SelectionChanged(object sender, EventArgs e)
{
    if (this.radGridView1.SelectedRows.Count > 0)
    {
        this.radGridView1.Refresh();
    }
 }

Let me know
richard
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 08:09 PM
Yes i did, but i'm not using the multiselect, just scrolling.

Rafael
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 08:15 PM
Hi Rafael,

If the above workaround isn't working for you (even without multiselect), please can you describe your situation in further detail and I will do my best to help.

i have tried the workaround with multiselect turned off and it does seem to help any delay in scrolling.

Best regards,
Richard
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 08:23 PM
I have a very simple scenario, no custom cells, 500 rows, 8 columns:

List<WineSpectatorScore> result = WineSpectatorManager.GetLastestWinesImported();
radGridViewWines.DataSource = result;
radGridViewWines.MasterTemplate.BestFitColumns();

I tried the
radGridViewWines.Refresh();
but it doesn't even get fired as i don't select rowns, i only scroll the list with the mouse.

Rafael
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 08:30 PM
even on the demos (customize/Conditional formating for ex), there a delay with mouse scrolling

Rafael

EDIT: i had a conditional formatting for a column, removed it but nothing changed)
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 08:32 PM
Hi Rafael,

How are you scrolling with the mouse (I am trying to replicate your issue)
E.g.
+ selecting a row, and then using the arrow on the vertical scrollbar
+ selecting a row, and using the mouse wheel
+ some other scenario?

Thanks
Richard
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 08:33 PM
selecting a row, and using the mouse wheel
0
Ramius
Top achievements
Rank 1
answered on 14 Nov 2010, 10:16 PM

Hi Emanuel,

why is unbound mode always slower than bound mode ?

Regards,

Ramius

0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 11:53 PM
Hello Raymond,

Glad to hear that your first issue with loading performance is now fixed by using DeferRefresh()

With regard to your second issue, I believe that this will be helped by implementing the the above solution with RadGridView.Refresh() in SelectionChanged.

Rafael,
I can't replicate your issue with scrolling using the mouse wheel. On my system, the rows scroll two at a time and seems as fast (though not as smooth as it is scrolling two rows at a time).
If you can post a sample to replicate the issue, I'll be happy to take a look.

Richard
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 11:56 PM
As a sample you can check the demos (customize/Conditional formating for ex).
Do you notice a delay with mouse scrolling too?

Rafael
0
Richard Slade
Top achievements
Rank 2
answered on 15 Nov 2010, 12:19 AM
Hi,

Yes, I can see that there is some delay when scrolling quickly through the records using the mouse wheel. In this case my advice would be to open a support ticket for this.

Apologies I cannot offer a workaround this time.
Richard
0
Rafael
Top achievements
Rank 1
answered on 15 Nov 2010, 12:35 AM
ok thanks! i'll do that :)
0
Raymond
Top achievements
Rank 1
answered on 15 Nov 2010, 09:41 AM
Hi

I also reported this as bug becasue I have problems not only during using mouse wheel.

Bug Report ID:366641 -- Scrolling sometimes doesn`t work or in other scenarion there is big lag
0
Jack
Telerik team
answered on 17 Nov 2010, 05:05 PM
Hi guys,

Thank you for reporting this issue.

Yes, we found that the scrolling is slow in some cases (for example when using checkbox column). The issue is logged in our issue tracking system and we will try to address it in our upcoming service pack.

Should you have any further questions, do not hesitate to ask.

Best wishes,
Jack
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
0
Raymond
Top achievements
Rank 1
answered on 18 Nov 2010, 09:31 AM
I cannot find this issue in PITS.

http://www.telerik.com/support/pits.aspx#/public/winforms/2010-q3-sp+

How can I track if this issue is fixed? Can you give me direct link?

Reagrds
0
Alexander
Telerik team
answered on 18 Nov 2010, 02:18 PM
Hello Raymond,

The issues you reported are logged in PITS here: Scrolling and Multiselection. When a new item is created, it does not become visible immediately, but should be first synchronized with the PITS which may take some time. Feel free to follow the provided links in order to track the status of the issues.

Best regards,
Alexander
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Raymond
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Rafael
Top achievements
Rank 1
Ramius
Top achievements
Rank 1
Jack
Telerik team
Alexander
Telerik team
Share this question
or