Unplanned
Last Updated: 19 Mar 2019 10:29 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 29 Sep 2016 10:53
Category: GridView
Type: Bug Report
4
FIX. RadGridView - nested hierarchical levels are not loaded after LoadLayout
To reproduce: use the following code snippet, save the layout and load it afterwards. You will notice that only the master and the first child template are successfully loaded.

public Form1()
{
    InitializeComponent();
    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    for (int i = 0; i < 5; i++)
    {
        dt.Rows.Add(i, "Parent" + i);
    }

    this.radGridView1.MasterTemplate.DataSource = dt;
    this.radGridView1.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    //child level 1
    GridViewTemplate template = new GridViewTemplate();
    template.DataSource = GetData(5, 20, 0, 5);
    template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    radGridView1.MasterTemplate.Templates.Add(template);

    GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
    relation.ChildTemplate = template;
    relation.RelationName = "ParentChild";
    relation.ParentColumnNames.Add("Id");
    relation.ChildColumnNames.Add("ParentId");
    radGridView1.Relations.Add(relation);

    //child level 2
    GridViewTemplate template2 = new GridViewTemplate();
    template2.DataSource = GetData(20, 40, 5, 20);
    template2.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    template.Templates.Add(template2);

    GridViewRelation relation2 = new GridViewRelation(template);
    relation2.ChildTemplate = template2;
    relation2.RelationName = "ParentChild";
    relation2.ParentColumnNames.Add("Id");
    relation2.ChildColumnNames.Add("ParentId");
    radGridView1.Relations.Add(relation2);

    //child level 3
    GridViewTemplate template3 = new GridViewTemplate();
    template3.DataSource = GetData(40, 100, 20, 40);
    template3.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    template2.Templates.Add(template3);

    GridViewRelation relation3 = new GridViewRelation(template2);
    relation3.ChildTemplate = template3;
    relation3.RelationName = "ParentChild";
    relation3.ParentColumnNames.Add("Id");
    relation3.ChildColumnNames.Add("ParentId");
    radGridView1.Relations.Add(relation3);

    //child level 4
    GridViewTemplate template4 = new GridViewTemplate();
    template4.DataSource = GetData(100, 200, 40, 100);
    template4.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    template3.Templates.Add(template4);

    GridViewRelation relation4 = new GridViewRelation(template3);
    relation4.ChildTemplate = template4;
    relation4.RelationName = "ParentChild";
    relation4.ParentColumnNames.Add("Id");
    relation4.ChildColumnNames.Add("ParentId");
    radGridView1.Relations.Add(relation4);
}

private object GetData(int from, int to, int parentFrom, int parentTo)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Name", typeof(string));  
    dt.Columns.Add("ParentId", typeof(int));
    Random rand = new Random();
    for (int i = from; i < to; i++)
    {
        dt.Rows.Add(i, "Child" + i, rand.Next(parentFrom, parentTo));
    }
    return dt;
}

private void radButton1_Click(object sender, EventArgs e)
{
    string s = "default.xml";
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
    dialog.Title = "Select a xml file";
    if (dialog.ShowDialog() == DialogResult.OK)
    {
        s = dialog.FileName;
    }
    this.radGridView1.SaveLayout(s);
}

private void radButton2_Click(object sender, EventArgs e)
{
    string s = "default.xml";
    OpenFileDialog dialog = new OpenFileDialog();
    dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
    dialog.Title = "Select a xml file";
    if (dialog.ShowDialog() == DialogResult.OK)
    {
        s = dialog.FileName;
    }
    this.radGridView1.LoadLayout(s);
}


Workaround: grid templates for the inner levels are recreated after loading the layout. Their DataSource is null and the existing relations points to the old templates. Clear the relations and setup them again with the new  child template instances.
2 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 19 Mar 2019 10:29
Hello, Wardeaux,

Currently, the issue is with status Approved. This means that a fix is not introduced yet. It is definitely in our TODO list but I can't give you an exact time frame when the issue will be addressed.

Please make sure that you cast your vote for it which will increase its priority. You can subscribe for status changes and add your comments in order to get notified once any changes occur with the item. 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 
 
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Wardeaux
Posted on: 13 Mar 2019 18:48

Is there a permanent fix on the schedule for this?