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

3rd Level Hierarchy Difficulty

10 Answers 131 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 04 Oct 2011, 11:32 PM
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;
 
}

10 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 05 Oct 2011, 07:17 AM
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
0
Victoria F
Top achievements
Rank 1
answered on 11 Oct 2011, 02:37 PM
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);

0
Karl
Top achievements
Rank 1
answered on 11 Oct 2011, 10:26 PM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2011, 07:00 AM
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
0
Victoria F
Top achievements
Rank 1
answered on 12 Oct 2011, 02:58 PM
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.
0
Victoria F
Top achievements
Rank 1
answered on 12 Oct 2011, 04:48 PM
Hello Emanuel,
Can I Auto expand all hierarchies?
I can not find the property.
 
Thank you ,
Victoria.
0
Accepted
Jack
Telerik team
answered on 13 Oct 2011, 12:21 PM
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.

0
Victoria F
Top achievements
Rank 1
answered on 13 Oct 2011, 02:46 PM
Thank you Jack ,
This works.
Victoria.
0
divyesh
Top achievements
Rank 1
answered on 25 Mar 2014, 02:47 PM
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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Mar 2014, 11:20 AM
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.

 
Tags
GridView
Asked by
Karl
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Victoria F
Top achievements
Rank 1
Karl
Top achievements
Rank 1
Jack
Telerik team
divyesh
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or