1.在列表编辑器中
2.在属性编辑器中
3.实现代码如下
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using
System;
using System.ComponentModel;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
namespace XSolution1.Module
{
[DefaultClassOptions]
public class Employee : BaseObject
{
public Employee(Session session) : base (session) { }
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
SetPropertyValue( " Name " , ref _Name, value);
}
}
private string _Note;
public string Note
{
get
{
return _Note;
}
set
{
SetPropertyValue( " Note " , ref _Note, value);
}
}
private Department _Department;
public Department Department
{
get
{
return _Department;
}
set
{
SetPropertyValue( " Department " , ref _Department, value);
}
}
}
}
using System.ComponentModel;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
namespace XSolution1.Module
{
[DefaultClassOptions]
public class Employee : BaseObject
{
public Employee(Session session) : base (session) { }
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
SetPropertyValue( " Name " , ref _Name, value);
}
}
private string _Note;
public string Note
{
get
{
return _Note;
}
set
{
SetPropertyValue( " Note " , ref _Note, value);
}
}
private Department _Department;
public Department Department
{
get
{
return _Department;
}
set
{
SetPropertyValue( " Department " , ref _Department, value);
}
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using
System;
using System.ComponentModel;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.Localization;
using DevExpress.Persistent.Base.General;
namespace XSolution1.Module
{
[DefaultClassOptions]
public class Department : BaseObject, IHCategory
{
private string name;
private Department parent;
private void CheckCircularReferences(Department obj)
{ Department currentObj = obj; while (currentObj != null )
{
if (currentObj == this ) { throw new UserFriendlyException(ExceptionId.CircularReference);
} currentObj = currentObj.Parent; } }
public Department(Session session) : base (session) { }
public Department(Session session, string name) : this (session) { this .name = name; }
[Association( " DepartmentParent-DepartmentChild " )]
public XPCollection < Department > Children
{
get { return GetCollection < Department > ( " Children " ); }
}
[Persistent, Association( " DepartmentParent-DepartmentChild " )]
public Department Parent
{
get { return parent; }
set {
if ( ! IsLoading)
{
CheckCircularReferences(value);
}
parent = value; OnChanged( " Parent " );
}
}
public string Name
{
get { return name; }
set { name = value; OnChanged( " Name " ); }
}
IBindingList ITreeNode.Children
{
get { return Children as IBindingList; }
}
ITreeNode IHCategory.Parent
{
get { return Parent as IHCategory; }
set { Parent = value as Department; }
}
ITreeNode ITreeNode.Parent
{
get { return Parent as ITreeNode; }
}
}
}
using System.ComponentModel;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.Localization;
using DevExpress.Persistent.Base.General;
namespace XSolution1.Module
{
[DefaultClassOptions]
public class Department : BaseObject, IHCategory
{
private string name;
private Department parent;
private void CheckCircularReferences(Department obj)
{ Department currentObj = obj; while (currentObj != null )
{
if (currentObj == this ) { throw new UserFriendlyException(ExceptionId.CircularReference);
} currentObj = currentObj.Parent; } }
public Department(Session session) : base (session) { }
public Department(Session session, string name) : this (session) { this .name = name; }
[Association( " DepartmentParent-DepartmentChild " )]
public XPCollection < Department > Children
{
get { return GetCollection < Department > ( " Children " ); }
}
[Persistent, Association( " DepartmentParent-DepartmentChild " )]
public Department Parent
{
get { return parent; }
set {
if ( ! IsLoading)
{
CheckCircularReferences(value);
}
parent = value; OnChanged( " Parent " );
}
}
public string Name
{
get { return name; }
set { name = value; OnChanged( " Name " ); }
}
IBindingList ITreeNode.Children
{
get { return Children as IBindingList; }
}
ITreeNode IHCategory.Parent
{
get { return Parent as IHCategory; }
set { Parent = value as Department; }
}
ITreeNode ITreeNode.Parent
{
get { return Parent as ITreeNode; }
}
}
}