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

Master-Detail contains no detail data

3 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 1
Danny asked on 19 Apr 2011, 11:17 AM
Hello,

I'm evaluating the GridView component. In any case there will be no detail data bound to the grid.
Only if I'm using AutoGenerateHierarchy = true the detail will appear.

Previous steps in the designer:
- Defined two columns for master template (Vorname, Nachname) -> FieldName and HeaderText
- Created a new template called 'childTemplate' and add two columns (Firma, Ort) -> FieldName and HeaderText

As follow the code behind:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace TestForm
{
    public partial class Form1 : Form
    {
        private readonly List<Person> _personen = new List<Person>();
 
        public Form1()
        {
            InitializeComponent();
 
 
            _personen.AddRange(new[]
                              {
                                  new Person {Vorname = "Danny", Nachname = "Meier", Jobs = new List<Job>
                                                                              {
                                                                                  new Job {Firma = "Heiniger & Partner AG", Ort = "Wetzikon"},
                                                                                  new Job {Firma = "Scor AG", Ort = "Zürich"},
                                                                                  new Job {Firma = "ERNI Consulting AG", Ort = "Zürich"}
                                                                              }},
                                  new Person {Vorname = "Michael", Nachname = "Bolliger", Jobs = new List<Job>()},
                                  new Person {Vorname = "Daniel", Nachname = "Kuster", Jobs = new List<Job>
                                                                                              {
                                                                                                  new Job {Firma = "Heiniger & Partner AG", Ort = "Wetzikon"}
                                                                                              }}
                              });
        }
 
        private void Form1Load(object sender, EventArgs e)
        {
            radGridView1.AutoGenerateHierarchy = false;
 
            var relation = new GridViewRelation(radGridView1.MasterTemplate, childTemplate);
            relation.ChildColumnNames.Add("Job");
            radGridView1.Relations.Add(relation);
 
            radGridView1.DataSource = _personen;
        }
    }
 
    public class Person
    {
        public string Vorname { get; set; }
        public string Nachname { get; set; }
        public List<Job> Jobs { get; set; }
    }
 
    public class Job
    {
        public string Firma { get; set; }
        public string Ort { get; set; }
    }
}

Thank you for any assistance.

Kind regards,
Danny

3 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 19 Apr 2011, 12:44 PM
Hello Danny,

It looks like you have missed specifying the parent and child column names for your relationship. Please have a look at this help topic for full information.

Hope that helps but let me know if you need further assistance.
Richard
0
Danny
Top achievements
Rank 1
answered on 19 Apr 2011, 12:48 PM
I don't think so.

I've tried to copy your sample from http://www.telerik.com/help/winforms/gridview-hierarchical-grid-object-relational-hierarchy-mode.html (the second one)! Or is this simple only useable for customers who also use your ORM framework?

Danny
0
Richard Slade
Top achievements
Rank 2
answered on 19 Apr 2011, 01:02 PM
Hello Danny,

no, this is not tied to using OpenAccess ORM. You can do this in your example with AutoGenerateHierarchy set to true, without having to specify anything else. Here is a sample that should help.

Form1.Designer.cs
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";
            // 
            // 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";
            ((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;
  
namespace RadControlsWinFormsApp1
{
    public partial class Form1 : Form
    {
        private readonly List<Person> m_people = new List<Person>();
  
        public Form1()
        {
            InitializeComponent();
  
            this.radGridView1.AutoGenerateHierarchy = true;
            m_people.AddRange(new[]
                              {
                                  new Person {Vorname = "Danny", Nachname = "Meier", Jobs = new List<Job>
                                                {
                                                    new Job {Firma = "Heiniger & Partner AG", Ort = "Wetzikon"},
                                                    new Job {Firma = "Scor AG", Ort = "Zürich"},
                                                    new Job {Firma = "ERNI Consulting AG", Ort = "Zürich"}
                                                }},
                                  new Person {Vorname = "Michael", Nachname = "Bolliger", Jobs = new List<Job>()},
                                  new Person {Vorname = "Daniel", Nachname = "Kuster", Jobs = new List<Job>
                                                {
                                                    new Job {Firma = "Heiniger & Partner AG", Ort = "Wetzikon"}
                                                }}
                              });
  
            this.radGridView1.DataSource = m_people;
  
        }
    }
  
    public class Person
    {
        public string Vorname { get; set; }
        public string Nachname { get; set; }
        public List<Job> Jobs { get; set; }
    }
  
    public class Job
    {
        public string Firma { get; set; }
        public string Ort { get; set; }
    }
  
}

Hope that helps
Richard
Tags
GridView
Asked by
Danny
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Danny
Top achievements
Rank 1
Share this question
or