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

Self Referencing Grid

7 Answers 354 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maarten
Top achievements
Rank 1
Maarten asked on 14 May 2012, 09:40 AM
Hi,

We are using the Self Referencing grid to show hierachical data which only has one parent and is always one level deep.
For Instance:
    Parent
     => Child 1
     => Child 2
     => Child 3

For some users the number of children can reach 10 000 records. The load time for these users is really slow. Currently we are retrieving the data and binding it via the datasource to the grid.

grid.DataSource = listOfData;


grid.Relations.AddSelfReference(grid.MasterTemplate, "Id""ParentId");
grid.TableElement.ShowSelfReferenceLines = true;

But if we remove the self referencing code all data is loaded very fast (off course without the hierarchical structure). Is there a trick to increase the performance? For instance not using the datasource to bind the data?

Many thx!







7 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 17 May 2012, 09:33 AM
Hello Maarten,

Thank you for writing.

To increase the performance of you application you can replace the SelfReference hierarchy mode of RadGridView with load-on-demand hierarchy. Using this approach the internal self-reference structure of RadGridView will not be created neither processed and data will be loaded only when expanding a parent row.

I hope this information is helpful.

All the best,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Maarten
Top achievements
Rank 1
answered on 22 May 2012, 12:24 PM
Hi Julian,

Thx for the answer!!

Load on demand will decrease the initial load time of the form but in our case that's not really the problem. The time to load the form / grid is acceptable, but the time it takes to expand the parent with the 10 000 childs is way to slow. Will the load time of one parent be faster in case of the load on demand radgridview?

The example below clearly demonstrate our problem.If you delete the lines of code related to the selfreferencing the data is presented very fast.
    radGridView1.Relations.AddSelfReference(radGridView1.MasterTemplate, "SomeDataId", "ParentDataId");
    radGridView1.TableElement.ShowSelfReferenceLines = true;

//DUMMY OBJECT
public class SomeData {
    public int SomeDataId { getset; }
    public int? ParentDataId { getset; }
    public string Name { getset; }
}

//FORM
public Form1() {
    InitializeComponent();
}
protected override void OnLoad(EventArgs e) {
    base.OnLoad(e);
    radGridView1.DataSource = CreateDummyData();
    radGridView1.Relations.AddSelfReference(radGridView1.MasterTemplate, "SomeDataId""ParentDataId");
    radGridView1.TableElement.ShowSelfReferenceLines = true;
}
private static List<SomeData> CreateDummyData() {
    List<SomeData> data = new List<SomeData>();
    SomeData someData = new SomeData{Name = Guid.NewGuid().ToString(), ParentDataId = null, SomeDataId = 0};
    data.Add(someData);
    for (int i = 1; i <= 10001; i++) {
        SomeData someChildData = new SomeData() { 
                                        Name = Guid.NewGuid().ToString(),
                                        ParentDataId = someData.SomeDataId,
                                        SomeDataId = i };
        data.Add(someChildData);
    }
    return data;
}
0
Maarten
Top achievements
Rank 1
answered on 22 May 2012, 01:12 PM
Hi,

I already tried to implement the load on demand for the example above. But the time to expand the parent with 10 000 childs takes even longer in the load on demand method. Once loaded however the scrolling is better...

Grtz Maarten
0
Julian Benkov
Telerik team
answered on 28 May 2012, 11:17 AM
Hi Maarten,

You can optimize the loading speed by using index-based setup of cell values. Here is a sample of load-on-demand hierarchy using your data collection with good performance:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace Lab.Grid
{
    public partial class GridLoadOnDemandHierarchy : MainForm
    {
        private RadGridView gridView = new RadGridView();
 
        public GridLoadOnDemandHierarchy()
        {
            InitializeComponent();
 
            this.gridView.Dock = DockStyle.Fill;
            this.gridView.Parent = this;
            this.gridView.BringToFront();
        }
 
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
 
            gridView.DataSource = CreateDummyData();
 
            GridViewTemplate childTemplate = CreateChildTemplate();
            this.gridView.Templates.Add(childTemplate);
 
            childTemplate.HierarchyDataProvider = new GridViewEventDataProvider(childTemplate);
            this.gridView.RowSourceNeeded += gridView_RowSourceNeeded;
        }
 
        void gridView_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
        {
            List<SomeData> data = CreateDummyData();
 
            for (int i = 0; i < data.Count; i++)
            {
                GridViewRowInfo row = e.Template.Rows.NewRow();
                row.Cells[0].Value = data[i].Name;
                row.Cells[1].Value = data[i].SomeDataId;
                row.Cells[2].Value = data[i].ParentDataId;
 
                e.SourceCollection.Add(row);
            }
        }
 
        private GridViewTemplate CreateChildTemplate()
        {
            GridViewTemplate template = new GridViewTemplate();
            template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
            GridViewTextBoxColumn namecolumn = new GridViewTextBoxColumn("Name");
            GridViewTextBoxColumn idColumn = new GridViewTextBoxColumn("ID");
            GridViewTextBoxColumn parentColumn = new GridViewTextBoxColumn("Parent");
             
            template.Columns.AddRange(namecolumn,
                idColumn,
                parentColumn);
 
            return template;
        }
 
        public class SomeData
        {
            public int SomeDataId { get; set; }
            public int? ParentDataId { get; set; }
            public string Name { get; set; }
        }
 
        private static List<SomeData> CreateDummyData()
        {
            List<SomeData> data = new List<SomeData>();
            SomeData someData = new SomeData { Name = Guid.NewGuid().ToString(), ParentDataId = null, SomeDataId = 0 };
            data.Add(someData);
            for (int i = 1; i <= 10001; i++)
            {
                SomeData someChildData = new SomeData()
                {
                    Name = Guid.NewGuid().ToString(),
                    ParentDataId = someData.SomeDataId,
                    SomeDataId = i
                };
                data.Add(someChildData);
            }
            return data;
        }
    }
}

I hope this helps.

Kind regards,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Wesley
Top achievements
Rank 1
answered on 31 May 2012, 09:39 AM
Hi Julian,

I tried your sample, but I still got poor performance.
It seemed that the bulk of the processor time went to rendering the grid. The gridView_RowSourceNeeded function executes very fast.
When I enabled "UseScrollbarsInHierarchy" on the grid, the grid performed fast again.

public Form1()
        {
            InitializeComponent();
            dummyGridView.Dock = DockStyle.Fill;
            dummyGridView.Parent = this;
            dummyGridView.BringToFront();
            dummyGridView.UseScrollbarsInHierarchy = true;
        }

0
Julian Benkov
Telerik team
answered on 05 Jun 2012, 10:05 AM
Hello Maarten,

The issue in this situation is the complex layout calculation and rendering of more RadGridView elements to the screen. We will continue working on performance optimizations regarding the internal structures used in our layout engine and the way the themes are applied during rendering. We hope that we will be able to provide a good solution regarding the desired optimizations in one of our next releases. Still, because of the complex nature of the issue, I am not able to provide you with any specific time frame. 

Greetings,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Maarten
Top achievements
Rank 1
answered on 05 Jun 2012, 10:46 AM
Hi Julian,

The implementation of the "Load on demand" instead of the "Self Referencing Grid" + enabling the "UseScrollbarsInHierarchy" on the grid did the trick (as explained by my collegeau Wesley). We now have again a performant grid and a satisfied client. So problem solved! :-)

Thx for the support!
Maarten
Tags
GridView
Asked by
Maarten
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Maarten
Top achievements
Rank 1
Wesley
Top achievements
Rank 1
Share this question
or