假设我有
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
}
}
我有:
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
}
}
我想要做的正是以下内容:
//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);
我得到的正是每个人旁边带有“+”号的网格视图问题是,“子”网格是空的,如果我尝试添加数据(默认情况下,它允许使用空的构造函数在课堂上)我抛出一个 NullArgumentException
有任何想法吗?我几乎要放弃了。我的问题是:我在所有项目上都使用自定义对象,它不像“你使用数据集,它可以使用等”,我知道,但我想知道是否有使用自定义对象的方法,或者我是否完成并且应该尝试数据集...
多谢你们