Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3988854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:18:08+00:00 2026-05-20T06:18:08+00:00

Suppose i have class Person { public int Id {get;set;} public string Name {get;set;}

  • 0

Suppose i have

class Person
{
    public int Id {get;set;}
    public string Name {get;set;}
    public List<Person> All {get;set;}

    public Person()
    {
    }

    public List<Person> GetAll()
    {
        //fills the list with person and returns
    }
}

and that i have:

class Address 
{
    public int PersonId {get;set;}
    public string theAddress {get;set;}
    public List<Address> All {get;set;}

    //constructor, etc

    public List<Address> GetAll()
    {
        //fills the address list and returns
    }
}

What im trying to do is exactly the following:

//filling the maintemplate with data
radGridView1.DataMember = "Person";
radGridView1.DataSource = new Person().GetAll();     

//address template, the child one
GridViewTemplate template = new GridViewTemplate();
template.DataSource = new Address().GetAll();
template.DataMember = "Address";
radGridView1.MasterTemplate.Templates.Add(template);

//now the relation between those 2 classes

GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "PersonAddress"; //just a name
relation.ParentColumnNames.Add("Id"); //field to be "joined" to create the relation
relation.ChildColumnNames.Add("PersonId"); //same as above
radGridView1.Relations.Add(relation);

and what i get is exactly a gridview with a “+” sign by the side of each Person
The problem is, the “child” grid is EMPTY, and if i try to add data (its, by default, allowed with an empty constructor in the class) i throw an NullArgumentException

Any ideas? im almost giving up. My problem is: i use custom objects on all projects, its not like “yo use datasets, its ready to use etc”, i know that, but i would like to know if there’s a way to use CUSTOM OBJECTS, or if im done and should try datasets…

Thanks guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:18:08+00:00Added an answer on May 20, 2026 at 6:18 am

    It looks like you are using the WinForms implementation. If that’s right, then this works for me fine. Please give this a go

    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 RadGridView_Hierarchy_CS
    {
        public partial class Form1 : Form
        {
    
            private List<Person> people = new List<Person>();
            private List<Address> addresses = new List<Address>();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                FillPeople();
                FillAddresses();
    
                radGridView1.DataSource = people;
    
                GridViewTemplate template = new GridViewTemplate();
                template.DataSource = addresses;
                radGridView1.MasterTemplate.Templates.Add(template);
    
                GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
                relation.ChildTemplate = template;
                relation.RelationName = "PersonAddress";
                relation.ParentColumnNames.Add("Id");
                relation.ChildColumnNames.Add("PersonId");
                radGridView1.Relations.Add(relation);
    
            }
    
            private void FillPeople()
            {
                Person richard = new Person();
                richard.Name = "Richard";
                richard.Id = 1;
                people.Add(richard);
                Person bob = new Person();
                bob.Name = "Bob";
                bob.Id = 2;
                people.Add(richard);
                Person mike = new Person();
                mike.Name = "Mike";
                mike.Id = 3;
                people.Add(mike);
            }
    
            private void FillAddresses()
            {
                Address house1 = new Address();
                house1.PersonId = 1;
                house1.Id = 1;
                house1.theAddress = "1 The Mews";
                addresses.Add(house1);
                Address house2 = new Address();
                house2.PersonId = 2;
                house2.Id = 2;
                house2.theAddress = "2 The Mews";
                addresses.Add(house2);
            }    
        }
    
        class Person 
        {     
            public int Id {get;set;}     
            public string Name {get;set;}     
    
    
            public Person()     
            { 
            }              
        }
    
        class Address  
        {
            public int Id { get; set; }   
            public int PersonId {get;set;}    
            public string theAddress {get;set;}     
    
            public Address()
            { 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say Suppose you have a class public class Person { public int PesronId{get;set;} public
Suppose I have one class Person ……… public class Person { public string Name
Suppose I have a class public class MyClass { private Set<String> set = new
For example, suppose I have a class: class Foo { public: std::string& Name() {
Suppose I have a class class person { char* name; public: void setname(const char*);
Suppose I have some per-class data: (AandB.h) class A { public: static Persister* getPersister();
Suppose I have the following class: public class TestBase { public bool runMethod1 {
Suppose I have a definition for a door: class Door { public void Lock()
Suppose I have this (outrageously) simplified XML schema: <xsd:complexType name=Person> <xsd:sequence> <xsd:element ref=FirstName/> <xsd:element
I have a model like this: class Person(models.Model,Subject): name = .. The class Subject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.