• About
    • Blog
    • Business Process
    • Charity Work
    • History
    • News
  • Services
    • Legacy System Support
    • Bespoke System Development
    • Web Design & Development
    • View all services
  • Products
  • Our work
    • Customers
    • Case Studies
  • Careers
  • Contact
Microsoft Partner - Application Development
17th March 2015

DevExpress XAF – Filter Child Field Based on Selected Parent

DevExpress PSP Knowledge
DevExpress XAF – Filter Child Field Based on Selected Parent

In many scenarios it is necessary to filter dropdown fields values based on a parent value entered within another field.

The requirement we had for this logic is that each time a parent is selected our code will fire and the child values will be refreshed and filtered to the values where their parent matches the selected parent in the parent field, if there is already a child selected then the child field will be reset to null. If a child is selected before the parent then the parent field will automatically be populated with the parent of the child.

The sample code below implements the above logic.

/// <summary>
/// Gets or sets the parent identifier.
/// </summary>
/// <value>
/// The parent identifier.
/// </value>
public Parent ParentId

get

return this.parentId;

set

this.SetPropertyValue<Parent>("ParentId", ref this.parentId, value); if (this.childId != null)

this.SetPropertyValue<Child>("ChildId", ref this.childId, null);

this.RefreshAvailableParentChildren();

/// <summary> /// Gets or sets the child identifier. /// </summary> /// <value> /// The child identifier. /// </value> [DataSourceProperty("AvailableParentChildren")] public Child ChildId

get

return this.childId;

set

this.SetPropertyValue<Child>("ChildId", ref this.childId, value); if (this.childId != null)

if (this.childId.ParentId != null)

this.SetPropertyValue<Parent>("ParentId", ref this.parentId, this.childId.ParentId);

/// <summary> /// Gets the available parent children. /// </summary> /// <value> /// The available parent children. /// </value> [BrowsableAttribute(false)] [VisibleInDetailViewAttribute(false)] public XPCollection<Child> AvailableParentChildren

get

if (this.availableParentChildren == null)

this.availableParentChildren = new XPCollection<Child>(Session); this.RefreshAvailableParentChildren();

return this.availableParentChildren;

/// <summary> /// Refreshes the available parent children. /// </summary> private void RefreshAvailableParentChildren()

if (this.availableParentChildren == null)

return;

if (this.parentId != null)

using (UnitOfWork uow = new UnitOfWork())

uow.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; uow.Connect(); ParentFilter parentFilter = uow.GetObjectByKey<ParentFilter>(this.Oid); if (this.childId != null)

if (parentFilter.childId.Oid != this.childId.Oid)

this.childId = null;

uow.CommitChanges(); uow.Disconnect();

else

this.childId = null;

if (this.parentId != null)

this.availableParentChildren.Criteria = CriteriaOperator.Parse("ParentId.Oid == ?", this.parentId.Oid);

if (this.availableParentChildren == null)

this.childId = null;

Share:
PSP IT Design & Development
About Us
  • Privacy Policy
  • History
  • Customers
  • News
  • Blogs
Services
  • Legacy System Modernisation
  • Website Design & Development
  • Bespoke Application Development
  • Outsource IT Strategy
  • All Services
Contact
  • 01775 722377
  • letstalk@psp-it.co.uk
  • Carver House, Apex Court, Spalding Office Park, Elsoms Way, Pinchbeck, Spalding,Lincolnshire, PE11 3UL

Terms & Conditions Privacy Policy

© PSP People Systems Process Ltd. 2022. All Rights Reserved.

MENU

MENU

  • About

    • Blog

    • Business Process

    • Charity Work

    • History

    • News

  • Services

    • Legacy System Support

    • Bespoke System Development

    • Web Design & Development

    • View all services

  • Products

  • Our work

    • Customers

    • Case Studies

  • Careers

  • Contact

© PSP People Systems Process Ltd. 2022. All Rights Reserved. Privacy Policy

give us a call
01775 722377
drop us an email