3rd Level Hierarchy Difficulty

11 posts, 2 answers
  1. Karl Golling
    Karl Golling avatar
    226 posts
    Member since:
    Jun 2005

    Posted 04 Oct 2011 Link to this post

    Hi,
    I am trying for a while now to figur out what I have wrong in setting up my 3 level relation. I keep getting an unspecified error if I try to open the 3rd level. Am I missing a little detail?
    Karl
    private void RadForm1_Load(object sender, EventArgs e)
    {
        this.t_TagTableAdapter.Fill(this.pAS3DataSet.T_Tag);
        this.t_Lex_BegriffTableAdapter.Fill(this.pAS3DataSet.T_Lex_Begriff);
        this.t_G_GendreTableAdapter.Fill(this.pAS3DataSet.T_G_Gendre);
        this.MyFilmsTableAdapter.Fill(this.pAS3DataSet.MyFilms);
        this.t_GlossarTableAdapter.Fill(this.pAS3DataSet.T_Glossar);
     
        GridViewComboBoxColumn myColumn = new GridViewComboBoxColumn();
        myColumn.Name = "Gendre";
        myColumn.HeaderText = "Gendre";
        myColumn.DataSource = this.tGGendreBindingSource;
        myColumn.ValueMember = "G_GendreID";
        myColumn.DisplayMember = "DE";
        myColumn.FieldName = "G_GendreID";
        myColumn.Width = 100;
        this.radGridView1.Columns.Add(myColumn);
     
        GridViewDecimalColumn dColumn = new GridViewDecimalColumn();
     
        // 2nd level
        // -------------Child --------------
        GridViewTemplate FilmTemplate = new GridViewTemplate();
        this.radGridView1.Templates.Add(FilmTemplate);
     
        //              set columns of filmtemplate
        //           GridViewDecimalColumn dColumn = new GridViewDecimalColumn();
        dColumn = new GridViewDecimalColumn("FilmID");
        dColumn.Name = "FilmID";
        dColumn.HeaderText = "FilmID";
        dColumn.FieldName = "FilmID";
        dColumn.IsVisible = false;
        FilmTemplate.Columns.Add(dColumn);
     
        dColumn = new GridViewDecimalColumn("GlossarID");
        dColumn.Name = "GlossarID";
        dColumn.HeaderText = "GlossarID";
        dColumn.FieldName = "GlossarID";
        dColumn.IsVisible = false;
        FilmTemplate.Columns.Add(dColumn);
     
        dColumn = new GridViewDecimalColumn("Anzahl");
        dColumn.Name = "Anzahl";
        dColumn.HeaderText = "Anzahl";
        dColumn.FieldName = "Anzahl";
        myColumn.Width = 100;
        FilmTemplate.Columns.Add(dColumn);
     
        GridViewTextBoxColumn tColumn = new GridViewTextBoxColumn();
        tColumn.HeaderText = "myFilmName";
        tColumn.FieldName = "myFilmName";
        tColumn.Width = 300;
        FilmTemplate.Columns.Add(tColumn);
        //   FilmTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
        // now create relations
     
        GridViewRelation relationGlos_Film = new GridViewRelation(radGridView1.MasterTemplate, FilmTemplate);
        relationGlos_Film.RelationName = "T_Glossar_MyFilms";
        relationGlos_Film.ParentColumnNames.Add("GlossarID");
        relationGlos_Film.ChildColumnNames.Add("GlossarID");
        this.radGridView1.Relations.Add(relationGlos_Film);
        FilmTemplate.DataSource = this.tFilmBindingSource;
        FilmTemplate.Caption = "Filme";
     
     
        // -------------Child Glossary--------------
        GridViewTemplate LexTemplate = new GridViewTemplate();
        this.radGridView1.Templates.Add(LexTemplate);
        GridViewDecimalColumn dxColumn = new GridViewDecimalColumn();
        // set columns of Glosstemplate
     
        dxColumn = new GridViewDecimalColumn("GlossarID");
        dxColumn.Name = "GlossarID";
        dxColumn.HeaderText = "GlossarID";
        dxColumn.FieldName = "GlossarID";
        dxColumn.IsVisible = false;
        LexTemplate.Columns.Add(dxColumn);
     
        dxColumn = new GridViewDecimalColumn("LexID");
        dxColumn.Name = "LexID";
        dxColumn.HeaderText = "LexID";
        dxColumn.FieldName = "LexID";
        dxColumn.IsVisible = false;
        LexTemplate.Columns.Add(dxColumn);
     
        GridViewTextBoxColumn txColumn = new GridViewTextBoxColumn();
        txColumn.Name = "myLex";
        txColumn.HeaderText = "myLex";
        txColumn.FieldName = "myLex";
        txColumn.Width = 300;
        LexTemplate.Columns.Add(txColumn);
     
        // now create relations
     
        GridViewRelation relationGlos_Lex = new GridViewRelation(radGridView1.MasterTemplate, LexTemplate);
        relationGlos_Lex.RelationName = "T_Glossar_T_Lex_Begriff";
        relationGlos_Lex.ParentColumnNames.Add("GlossarID");
        relationGlos_Lex.ChildColumnNames.Add("GlossarID");
        this.radGridView1.Relations.Add(relationGlos_Lex);
        LexTemplate.DataSource = this.tLexBegriffBindingSource;
        LexTemplate.Caption = "Lexika";
     
        // 3rd level
     
        GridViewTemplate SzenenTemplate = new GridViewTemplate();
        GridViewRelation relationFilm_Tag = new GridViewRelation(FilmTemplate, SzenenTemplate);
        relationFilm_Tag.RelationName = "T_FilmT_Tag";
        relationFilm_Tag.ParentColumnNames.Add("FilmID");
        relationFilm_Tag.ChildColumnNames.Add("FilmID");
        FilmTemplate.Templates.Add(SzenenTemplate);
        this.radGridView1.Relations.Add(relationFilm_Tag);
        //this.radGridView1.MasterTemplate.Templates[0].Templates.Add(SzenenTemplate);
     
        SzenenTemplate.Caption = "Szenen";
     
        dxColumn = new GridViewDecimalColumn("TagID");
        dxColumn.Name = "TagID";
        dxColumn.HeaderText = "TagID";
        dxColumn.FieldName = "TagID";
        dxColumn.IsVisible = true;
        SzenenTemplate.Columns.Add(dxColumn);
     
        dxColumn = new GridViewDecimalColumn("FilmID");
        dxColumn.Name = "FilmID";
        dxColumn.HeaderText = "FilmID";
        dxColumn.FieldName = "FilmID";
        dxColumn.IsVisible = true;
        SzenenTemplate.Columns.Add(dxColumn);
     
        SzenenTemplate.DataSource = this.tTagBindingSource;
     
    }

  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 05 Oct 2011 Link to this post

    Hello Karl,

    I cannot see any problems with the 3 lever hierarchy, please take a look at the following sample:
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    public partial class Form1 : Form
    {
        private RadGridView _radGridView;
     
        public Form1()
        {
            InitializeComponent();
            _radGridView = CreateGridView(this);
     
            LoadDataSourceAndCreateRelations();
        }
     
        public void LoadDataSourceAndCreateRelations()
        {
            var persons = new List<Person>();
     
            for (int i = 1; i <= 19; i++)
            {
                persons.Add(new Person(i, new Random(i).Next(101, 150), "Person" + i));
            }
     
            var cars = new List<Car>();
            for (int i = 101; i <= 150; i++)
            {
                cars.Add(new Car(i, new Random(i).Next(201, 300), "Car" + i));
            }
     
            var parts = new List<Part>();
            for (int i = 201; i <= 300; i++)
            {
                parts.Add(new Part(i, "Part" + i));
            }
     
            _radGridView.DataSource = persons;
     
            var carsTemplate = new GridViewTemplate();
            carsTemplate.ReadOnly = true;
            carsTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            var carsRelation = new GridViewRelation(_radGridView.MasterTemplate, carsTemplate);
            carsRelation.RelationName = "R1";
            carsRelation.ParentColumnNames.Add("CarId");
            carsRelation.ChildColumnNames.Add("Id");
            _radGridView.MasterTemplate.Templates.Add(carsTemplate);
            _radGridView.Relations.Add(carsRelation);
            carsTemplate.DataSource = cars;
     
            var partsTemplate = new GridViewTemplate();
            partsTemplate.ReadOnly = true;
            partsTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
            var partsRelation = new GridViewRelation(carsTemplate, partsTemplate);
            partsRelation.ParentColumnNames.Add("PartId");
            partsRelation.ChildColumnNames.Add("Id");
            carsTemplate.Templates.Add(partsTemplate);
            _radGridView.Relations.Add(partsRelation);
            partsTemplate.DataSource = parts;
        }
     
        public static RadGridView CreateGridView(Control parentControl)
        {
            var radGridView = new RadGridView();
            radGridView.Dock = DockStyle.Fill;
            radGridView.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
            if (parentControl != null)
            {
                parentControl.Controls.Add(radGridView);
            }
     
            return radGridView;
        }
    }
     
    public class Person
    {
        public int Id { get; set; }
     
        public int CarId { get; set; }
     
        public string Name { get; set; }
     
        public Person(int id, int carId, string name)
        {
            Id = id;
            CarId = carId;
            Name = name;
        }
    }
     
    public class Car
    {
        public int Id { get; set; }
     
        public int PartId { get; set; }
     
        public string Name { get; set; }
     
        public Car(int id, int partId, string name)
        {
            Id = id;
            PartId = partId;
            Name = name;
        }
    }
     
    public class Part
    {
        public int Id { get; set; }
     
        public string Name { get; set; }
     
        public Part(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }

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

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 11 Oct 2011 Link to this post

    Hello, I need help....
    To create a 3 - levels of the data hierarchy I implemented suggested in the forum posts.
    I have a problem with the third level.
    As you can see in the picture I was able to populate first two levels.
    When I click to open third layer I got generic error : Object reference not set to an instance of an object.
    Where might be the error and where can I track it? I just suspect that this is a problem with radGridView_AcctSummary.Relations.Add(ch_relation);
     When I click on the "+" button to open the next layer ChildViewExpanding event goes through just fine ....  but right after this event I still have this error .. can not fix it ...



    radGridView_AcctSummary.DataSource = gl_dtProgram; 
     
    //setup the master template
    GridViewTemplate template = new GridViewTemplate();           
    template.ReadOnly = true;
    template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
    //create the relation
    GridViewRelation relation = new GridViewRelation(radGridView_AcctSummary.MasterTemplate, template);
    relation.ChildTemplate = template;
    relation.RelationName = "Program";
    relation.ParentColumnNames.Add("ic_program");
    relation.ChildColumnNames.Add("ic_program");
    radGridView_AcctSummary.MasterTemplate.Templates.Add(template);
    radGridView_AcctSummary.Relations.Add(relation);
    template.DataSource = dtLayerList;
                 
    //setup the child template
    GridViewTemplate ch_template = new GridViewTemplate();
    ch_template.ReadOnly = true;
    ch_template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    ch_template.DataSource = dtAvrg;
     
    //create the child relation
    GridViewRelation ch_relation = new GridViewRelation(template, ch_template);
    ch_relation.RelationName = "Layer";
    ch_relation.ParentColumnNames.Add("BCLayerName");
    ch_relation.ChildColumnNames.Add("BCLayerName");
    template.Templates.Add(ch_template);
    radGridView_AcctSummary.Relations.Add(ch_relation);

  5. Karl Golling
    Karl Golling avatar
    226 posts
    Member since:
    Jun 2005

    Posted 11 Oct 2011 Link to this post

    Hi Emanuel,

    Thank you so much for your simple to follow example. It works and it is a nice and easy script to follow. Nice support! I will model my code according to your suggestion in the next few days.

    Sorry I can't help out with Victoria's problem.

    Karl
  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 12 Oct 2011 Link to this post

    Hello guys,

    @Karl glad to be able to help.

    @Victoria, can you please post the contents of the ChildViewExpanding event? I believe that you are doing something in that event, and because of the async nature of the grid, it is throwing an exception later on. For testing this, just use a timer and fire it after 50 ms and move all your code in the tick event.

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

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  7. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 12 Oct 2011 Link to this post

    Hello Emanuel,
    Actually I do not have anything in ChildViewExpanding event. I just placed a message and error handling there trying to track the error..
    private void radGridView_AcctSummary_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e)
    {
       try
        {
             MessageBox.Show(e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n St Tr: " + ex.StackTrace, ex.Source, MessageBoxButtons.OK,
                                              MessageBoxIcon.Warning);
        }
    }
    I believe that this is a problem with the third level of relation ...
    During my testing I tried to plug in second and third templates making them as first and second levels of relation .. works fine.
    It means that this is something with relation between the second and third levels .. Should I specify somewhere in properties of the gridview that this gridview suppose to have more then 2 levels of relation?

    Victoria.
  8. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 12 Oct 2011 Link to this post

    Hello Emanuel,
    Can I Auto expand all hierarchies?
    I can not find the property.
     
    Thank you ,
    Victoria.
  9. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 13 Oct 2011 Link to this post

    Hi Victoria,

    Yes, you can expand all hierarchy levels by calling the ExpandAll method of GridViewTemplate:
    this.radGridView1.MasterTemplate.ExpandAll();

    Regarding the hierarchy issue, please find the answer to your question in your support ticket regarding it. Please avoid posting the same question twice, as this may slow down our response.

    Should you have other questions, we will be glad to assist you.
     
    All the best,
    Jack
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  10. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 13 Oct 2011 Link to this post

    Thank you Jack ,
    This works.
    Victoria.
  11. divyesh
    divyesh avatar
    6 posts
    Member since:
    Nov 2010

    Posted 25 Mar 2014 in reply to Emanuel Varga Link to this post

    Hi Emanuel,

    I am facing performance issue with hierarchy grid. Whenever there are few hundred records as a child, and when user tries to open that node, it takes few seconds to open up. Specifically i have noted that it happens when open hierarchy of last master record.

    public partial class Form4 : Form
    {
        private RadGridView _radGridView;
        public Form4()
        {
            InitializeComponent();
            _radGridView = CreateGridView(this);
     
            LoadDataSourceAndCreateRelations();
     
            this._radGridView.MasterTemplate.ExpandAll();
            this._radGridView.MasterTemplate.Templates[0].ExpandAll();
        }
     
        private void Form4_Load(object sender, EventArgs e)
        {
     
        }
     
        public void LoadDataSourceAndCreateRelations()
        {
            var cars = new List<Car>();
            List<Part> parts = new List<Part>();
     
            for (int i = 1; i <= 3; i++)
            {
                Car myCar = new Car(i, "Car" + i);
     
                for (int j = 1000; j <= 2010; j++)
                {
                    parts.Add(new Part(j, "Part" + j, i));
                }
                myCar.Parts = parts;
                cars.Add(myCar);
     
            }
     
            _radGridView.DataSource = cars;
     
            var partsTemplate = new GridViewTemplate();
            partsTemplate.ReadOnly = true;
            partsTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
            var partsRelation = new GridViewRelation(_radGridView.MasterTemplate, partsTemplate);
            partsRelation.ParentColumnNames.Add("Id");
            partsRelation.ChildColumnNames.Add("CarId");
            _radGridView.MasterTemplate.Templates.Add(partsTemplate);
            _radGridView.Relations.Add(partsRelation);
            partsTemplate.DataSource = parts;
        }
     
        public static RadGridView CreateGridView(Control parentControl)
        {
            var radGridView = new RadGridView();
            radGridView.Dock = DockStyle.Fill;
            radGridView.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
            if (parentControl != null)
            {
                parentControl.Controls.Add(radGridView);
            }
     
            return radGridView;
        }
    }
     
    public class Car
    {
        public int Id { get; set; }
     
        public string Name { get; set; }
     
        public List<Part> Parts;
     
        public Car(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }
     
    public class Part
    {
        public int Id { get; set; }
     
        public string Name { get; set; }
     
        public string Name1 { get; set; }
        public string Name2 { get; set; }
        public string Name3 { get; set; }
        public string Name4 { get; set; }
        public string Name5 { get; set; }
        public string Name6 { get; set; }
        public string Name7 { get; set; }
        public string Name8 { get; set; }
        public string Name9 { get; set; }
     
        public int CarId { get; set; }
     
        public Part(int id, string name, int carid)
        {
            Id = id;
            Name = name;
            Name1 = name;
            Name2 = name;
            Name3 = name;
            Name4 = name;
            Name5 = name;
            Name6 = name;
            Name7 = name;
            Name8 = name;
            Name9 = name;
     
            CarId = carid;
        }
    }

    Is performance an issue when data is shown in hierarchy format? Kindly guide.

    Best Regards,
    Divyesh Makwana
  12. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 28 Mar 2014 Link to this post

    Hello Divyesh,

    Thank you for contacting Telerik Support.

    I was able to reproduce the performance problem with our RadGridView. I confirm that it is an issue with Object Relational Hierarchy Mode. I have logged it in our Feedback Portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - Feedback Item.

    I have also updated your 
    Telerik points.

    Please refer to our Load-On-Demand Hierarchy help article if it is suitable for your scenario.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready