【发布时间】:2011-06-28 19:25:13
【问题描述】:
假设我有
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
有什么想法吗?我几乎要放弃了。我的问题是:我在所有项目上都使用自定义对象,它不像“你使用数据集,它可以使用等”,我知道,但我想知道是否有使用自定义对象的方法,或者我是否完成并且应该尝试数据集...
谢谢大家
【问题讨论】:
-
假设您已经看过分层网格的演示并阅读了 RadGrid 的文档,但是这里有一些直接的详细信息:telerik.com/help/aspnet-ajax/grdunderstandinghierarchy.html
-
好吧,你给我指出了一个解释 asp.net 网格的链接。我假设它们不是同一类型,对吗?如果我错了,请原谅,但我对付费组件完全陌生。它很有用,但第一次,你迷路了(就像我一样)。和编辑:我刚刚测试了一个数据集 + 2 个指向 2 个表的表适配器,你猜怎么着?相同的代码具有魅力(但使用数据集)。我会再次阅读您的链接,看看我是否可以从中获得有用的信息。非常感谢
-
在查看此链接documentation.devexpress.com/#WindowsForms/CustomDocument5496 之后,我才意识到我应该迁移到 DevExpress,因为他们刚刚解决了我的问题,就像我第一次尝试使用 Telerik 的网格显示主详细信息一样。当我下载他们的产品时,我期待“自动”识别我列表中的关联,但这并没有发生。由于我仍在评估他们的产品,我会退出并去开发。感谢 ivanov,感谢您的帮助和时间。
标签: c# winforms telerik radgridview