Skip to main content
A newer version of this page is available. .
All docs
V20.2

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.

Step-by-Step Instructions

  1. 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)); }
       }
    }
    
  2. 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.

    xaf blazor filter lookup editor

  3. 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;
             }
          }
       }
    }
    
  4. 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:

    xaf blazor filter lookup editor

     

    xaf blazor filter lookup editor

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.

Next Lesson

Format a Property Value

See Also