Filter Lookup Editor Data Source
- 2 minutes to read
This lesson explains how to filter data displayed in a lookup editor. This editor is used in the Detail Views for reference properties and contains a list of objects of another related class.
Note
Before you proceed, take a moment to review the following lessons:
Step-by-Step Instructions
Specify a Many-to-Many relationship between the Position and Department classes. For more information, refer to the Set a Many-to-Many Relationship (XPO) lesson.
[DefaultClassOptions] [System.ComponentModel.DefaultProperty(nameof(Title))] public class Department : BaseObject { //... [Association("Departments-Positions")] public XPCollection<Position> Positions { get { return GetCollection<Position>(nameof(Positions)); } } } [DefaultClassOptions] [System.ComponentModel.DefaultProperty(nameof(Title))] public class Position : BaseObject { //... [Association("Departments-Positions")] public XPCollection<Department> Departments { get { return GetCollection<Department>(nameof(Departments)); } } }
In the MySolution.Module project, open the “Model.DesignedDiffs.xafml” file in the Model Editor. Navigate to the BOModel | MySolution.Module.BusinessObjects node. Expand the Contact child node and select the Position child node.
Set the node properties as follows:
- Set the DataSourceProperty property to
Department.Positions
. - Set the DataSourcePropertyIsNullMode property to
SelectAll
.
- Set the DataSourceProperty property to
Replace the Department property declaration with the following code:
[Association("Department-Contacts", typeof(Department)), ImmediatePostData] public Department Department { get {return department;} set { SetPropertyValue(nameof(Department), ref department, value); // Clear Position and Manager properties if the Department has been changed. if(!IsLoading) { Position = null; if(Manager != null && Manager.Department != value) { Manager = null; } } } }
Run the application. Specify the Positions property for Department objects. Invoke a Contact Detail View. The Position editor dropdown lists Positions assigned to the Department object:
Detailed Explanation
In step 2, you specify the following:
- The Position lookup editor displays the Department.Positions collection.
- The Position lookup editor displays all existing objects in the Contact.Position editor when the Department.Positions property is not specified.