Self Reference Hierarchy not working on child template

15 posts, 2 answers
  1. Wesley
    Wesley avatar
    4 posts
    Member since:
    Oct 2010

    Posted 19 Feb 2011 Link to this post

    Self Reference Hierarchy only seems to work on MasterTemplate.  I would like to have the following hierarchy:
    Group
    > Category
       > Category
          > Product
    Where category can have any number of levels.  If I make MasterTemplate the categories and then AddSelfReference, it works fine, but if I have groups at the MasterTemplate level and then have a CategoryTemplate and AddSelfReference I only get one level of categories.

    GroupCategory relation is Group.id = Category.groupId

    I have tried this:
    this.radGridView1.Relations.AddSelfReference(this.CategoryTemplate, "id", "parentId");
    and
    this.radGridView1.Relations.AddSelfReference(this.radGridView1.Templates[0], "id", "parentId");
    and these both show only one level of categories.

    With categories at the root (MasterTemplate) this works:
    this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "id", "parentId");
    I get several levels of categories.
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Feb 2011 Link to this post

    Hello Wesley,

    I would like to find out a bit more about what you're wanting to do. A self referencing hierarchy would include a simple Id / ParentId structure whch doesn't look like what you're try to do with the group>category>product unless that were all from the same data source with the above structure.

    If you have a datasource for each group, category and product, then you would create a simple hierarchy with a template added to the RadGridView templates for category, and then a product template added to the category template.

    I hope this helps, but let me know if you need more information
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Wesley
    Wesley avatar
    4 posts
    Member since:
    Oct 2010

    Posted 19 Feb 2011 Link to this post

    I have one dataset, with three tables, groups table, categories table, and product table.  I am not as much worried about the Product table at the moment as I am trying to get the category hierarchy to load properly.  A grouptableadapter gets created for the group table when I select it from the dataset, and a categorytableadapter gets created for the category table when I select it from the dataset.
    The category table does have a id/parentId columns/relationship, and works when I just use the category.  I do not get why having a top level relationship effects the categorytemplate referencing itself.
    I do not know how I would set it up manually because I do not know how many levels to go down.
    For Example:
    Level 1: GroupTemplate
    Level 2: CategoryTemplate
    Level 3: CategoryTemplate

    Relations:
    Parent Template: GroupTemplate
    Parent Field: id
    Child Template: CategoryTemplate
    Child Field: groupId

    Parent Template: CategoryTemplate
    Parent Field: id
    Child Template: CategoryTemplate
    Child Field: parentId

    Without the self reference, I guess the only way to do it would be to handle the databind complete or formatting events or some event after the datasource has been bound and figure out if it has rows and if so set the CategoryTemplate to it and somehow bind again and keep doing that until it has no rows, then assign the ProductTemplate.  Not even sure if that will work.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Feb 2011 Link to this post

    Hello Wesley,

    I have to confess I am confused by what you have explained. The hierarchy grid (for non-self-referencing hierarchy) a source for each level that you wish to represent. So, taking your group >> category >> product, each would have a data source.

    Group
    Id
    Name

    Category
    Id
    GroupId
    Name

    Product
    Id
    CategoryId
    Name

    Based on this, you would have a 3-level hierarchy. Perhaps I have mis-understood your requirement. However, what I have understood is that your category table itself is self referencing. Is that correct? If so, then I am not sure if this scenario is supported. Please can you confirm and if that's correct then I will look to see if I can see if/how it can be done.
    Thanks
    Richard
  6. Wesley
    Wesley avatar
    4 posts
    Member since:
    Oct 2010

    Posted 19 Feb 2011 Link to this post

    Hi Richard,
    Yes, you understand it correctly, the three tables have exactly those fields, although you should also include the "parentId" field in the Category table that references the id field in the same table..  Yes, I do have a three level hierarchy.  The category level has an arbitrary number of level.

    Group table:
    id | name
    1 | Group 1

    Category table:
    id | name         | groupId | parentId
    1 | Category 1 | 1           | Null
    2 | Category 2 | Null       | 1

    Product table:
    id | name       | categoryId
    1 | Product 1 | 2

    Hierarchy:
    Group 1
    > Category 1
       > Category 2
          > Product 1

    I would definitely appreciate any help in figuring out how this can be accomplished.

    I guess I could flatten the Group and Category tables into one table and add an additional column called isGroup, as they are kind of the same thing except groups should never contain products.  Although if I went with that approach, I would have to adjust id numbers since I would have conflicts if they were both in the same table.
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Feb 2011 Link to this post

    Hi Wesley,

    I'll have a look into it for you, but will need to be tomorrow now as it's 1am here. I'm pretty sure that this mix of self reference hierarchy and regular hierarchy is not supported, but I will get back to you as soon as I can.
    Regards,
    Richard
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Feb 2011 Link to this post

    Hi Wesley,

    I've had a quick look and I don't believe it's supported (though I still want to confirm). Also though, you said you are using datasets? The self referencing hierarchy only currently supports object based data. I'll see tomorrow if it can be structured differently to do what you need.
    Richard
  9. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 20 Feb 2011 Link to this post

    Morning Wesley,

    Ok, as far as I'm aware, the RadGridView supports a self referencing hierarchy as a single source method of getting all source data to display. You can't mix relational and self-referencing.

    My advice here would be to flatten out your structure completely. You have "Name" in all tables and the rest of the columns are just Id's so in my view it would make sense to have one self-referencing data source (as a object datasource). You could also add a type to identify if it was a group, category or product which you could use to distinguish it if you needed to perform any cell formatting, or indeed add an additional image column to distinguish them .

    I've added below a very simple exmaple of a self referencing grid using your examle columns.

    Designer File
    namespace RadControlsWinFormsApp1
    {
        partial class Form1
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components;
      
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
      
            #region Windows Form Designer generated code
      
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
                this.SuspendLayout();
                // 
                // radGridView1
                // 
                this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.radGridView1.Location = new System.Drawing.Point(0, 0);
                this.radGridView1.Name = "radGridView1";
                this.radGridView1.Size = new System.Drawing.Size(284, 262);
                this.radGridView1.TabIndex = 0;
                this.radGridView1.Text = "radGridView1";
                this.radGridView1.ChildViewExpanded += new Telerik.WinControls.UI.ChildViewExpandedEventHandler(this.radGridView1_ChildViewExpanded);
                this.radGridView1.DataBindingComplete += new Telerik.WinControls.UI.GridViewBindingCompleteEventHandler(this.radGridView1_DataBindingComplete);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(284, 262);
                this.Controls.Add(this.radGridView1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.Load += new System.EventHandler(this.Form1_Load);
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
                this.ResumeLayout(false);
      
            }
      
            #endregion
      
            private Telerik.WinControls.UI.RadGridView radGridView1;
        }
    }

    Form1.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
      
    namespace RadControlsWinFormsApp1
    {
        public partial class Form1 : Form
        {
      
            private List<Data> dataList;
      
      
            public Form1()
            {
                InitializeComponent();
            }
      
            private void Form1_Load(object sender, EventArgs e)
            {
                dataList = new List<Data>();
      
      
                dataList.Add(new Data(1, "Group1", null, "Group"));
                dataList.Add(new Data(2, "Category1", 1, "Category"));
                dataList.Add(new Data(3, "Category2", 2, "Category"));
                dataList.Add(new Data(4, "Product1", 3, "Product"));
      
                this.radGridView1.DataSource = dataList;
      
                radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "Id", "ParentId");
                this.radGridView1.MasterTemplate.BestFitColumns();
            }
      
            private void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e)
            {
                this.radGridView1.MasterTemplate.BestFitColumns();
            }
      
      
            private void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
            {
                this.radGridView1.Columns["DataType"].IsVisible = false;
                this.radGridView1.Columns["ParentId"].IsVisible = false;
            }
      
        }
      
      
        public class Data
        {
            public Data(int id, string name, int? parentId, string dataType)
            { this.Id = id; this.Name = name; this.ParentId = parentId; this.DataType = dataType; }
      
            public int Id
            { get; set; }
      
            public string Name
            {get; set;}
      
            public int? ParentId
            { get; set; }
      
            public string DataType
            { get; set; }
        }
      
    }

    Hope you find that helpful, but let me know if I can help further
    Richard
  10. Wesley
    Wesley avatar
    4 posts
    Member since:
    Oct 2010

    Posted 20 Feb 2011 Link to this post

    Ok :-).  Thanks so much for your help.
  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 20 Feb 2011 Link to this post

    You're welcome Wesley. Please remember to mark helpful posts as answer, and do let me know if you need further advice
    Richard
  12. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Mar 2011 Link to this post

    Hello,

    Just to let you know that in the Q1 2011 Release, Telerik introduced the ability to have mixed mode hierarchies. I.e Self reference mixed with standard.

    Hope that helps
    Richard
  13. Matthew Link
    Matthew Link avatar
    13 posts
    Member since:
    Oct 2009

    Posted 04 Apr 2011 Link to this post

    I'm going to chime in here because the mixed mode is exactly what I'm looking for.  Can you point me in the direction of any documentation or samples of it?  I see that it's mentioned in the Version Release Notes, but I can't find a reference to it in the documentation anywhere.

    Thanks!
    Matthew
  14. Answer
    Matthew Link
    Matthew Link avatar
    13 posts
    Member since:
    Oct 2009

    Posted 04 Apr 2011 Link to this post

    And as usual, the surest way to find an answer is to post a public question about it.   I just found this blog post that explains how to do it.

    http://blogs.telerik.com/blogs/posts/11-03-07/re_mixed_hierarchy_mode_in_radgridview_for_winforms.aspx

  15. Bartlomiej
    Bartlomiej avatar
    1 posts
    Member since:
    May 2012

    Posted 28 Dec 2012 Link to this post

    I'm working with telerik winforms version 2012.1.321.40. As mixed mode works great if you use self reference in Master template, it doesn't works in child template. Is there any plan to change it? 
  16. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 28 Dec 2012 Link to this post

    Hi Bartlomiej,

    Thank you for writing.

    Currently, we do not have plans to support binding to self referencing data for child templates. Our team will take your suggestion into considerations for future releases.

    Let me know if you have further queries.

    All the best,
    Boryana
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready