Ticket T362128
Visible to All Users

How to show a non-persistent class DetailView and filter related persistent lookup editors dynamically

created 9 years ago

Hello

I have a non persistent detail view that is shown though code using an action in the normal way .

On the detail view created there are two fields both of which have lookup list views. I would like to filter the second field lookup list view by setting it's criteria dynamically based on the value selected in the first field lookup list view. I have set the non persistent first field to immediate post data and was wondering what method you would recommend to achieve this?

I'm wondering whether I should add a handler for the control changed event and then dynamically filter the second lookup list view collection source within this routine, but am unsure how to obtain the correct view controller to implement this method.

Thanks

John

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello John,

I have just crafted a small sample for your scenario and attached a video showing its results in action.

Visual Basic
Imports System Imports System.ComponentModel Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Actions Imports DevExpress.ExpressApp.DC Imports DevExpress.Persistent.Base Namespace MainDemo.Module.BusinessObjects <DomainComponent> Public Class NonPersistentClass   Implements INotifyPropertyChanged   Private department_Renamed As Department   <ImmediatePostData>   Public Property Department() As Department    Get     Return department_Renamed    End Get    Set(ByVal value As Department)     If department_Renamed Is value Then      Return     End If     department_Renamed = value     OnPropertyChanged("Department")    End Set   End Property   Private manager_Renamed As Contact   <DataSourceCriteria("Department.Oid == '@This.Department.Oid'")>   Public Property Manager() As Contact    Get     Return manager_Renamed    End Get    Set(ByVal value As Contact)     If manager_Renamed Is value Then      Return     End If     manager_Renamed = value     OnPropertyChanged("Manager")    End Set   End Property   Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged   Protected Overridable Sub OnPropertyChanged(ByVal propertyName As String)    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))   End Sub End Class Public Class T362128   Inherits WindowController   Public Sub New()    TargetWindowType = WindowType.Main    CType(New SimpleAction(Me, "T362128", "View", Sub(s, e)     Dim persistentType As Type = GetType(Contact)     Dim persistentObjectSpace As IObjectSpace = Application.CreateObjectSpace(persistentType)     Dim dv As DetailView = Application.CreateDetailView(persistentObjectSpace, New NonPersistentClass())     dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit     e.ShowViewParameters.CreatedView = dv    End Sub), SimpleAction)   End Sub End Class End Namespace

C#
using System.ComponentModel; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.DC; using DevExpress.Persistent.Base; namespace MainDemo.Module.BusinessObjects { [DomainComponent] public class NonPersistentClass : INotifyPropertyChanged { private Department department; [ImmediatePostData] public Department Department { get { return department; } set { if(department == value) { return; } department = value; OnPropertyChanged("Department"); } } private Contact manager; [DataSourceCriteria("Department.Oid == '@This.Department.Oid'")] public Contact Manager { get { return manager; } set { if(manager == value) { return; } manager = value; OnPropertyChanged("Manager"); } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { if(PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } public class T362128 : WindowController { public T362128() { TargetWindowType = WindowType.Main; new SimpleAction(this, "T362128", "View", (s, e) => { Type persistentType = typeof(Contact);     IObjectSpace persistentObjectSpace = Application.CreateObjectSpace(persistentType);     DetailView dv = Application.CreateDetailView(persistentObjectSpace, new NonPersistentClass()); dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit; e.ShowViewParameters.CreatedView = dv; }); } } }

Please refer to the following XAF documentation to learn more on which core features I used here:
eXpressApp Framework > Task-Based Help > How to: Filter Lookup List Views  (Scenario 5 - Filter the Lookup Property Collection Based on the Current Object's Properties)
eXpressApp Framework > Frequently Asked Questions > Extend Functionality > How do I show a window that represents data in XAF?

    Comments (2)

      Hi Dennis

      Sorry for my slow reply on this and thanks very much for providing such a clear example of this functionality so quickly. As usual your support is excellent!

      This is pretty much exactly what I'm looking for but because we are using the ORM designer for our data model and I'm unsure how to implement the PropertyChanged event handler as in your example, however by using immediate post data the lookup list view is refreshing correctly.

      Thanks

      John

      Dennis Garavsky (DevExpress) 9 years ago

        John,

        I am happy to hear that this solution was helpful. Note that this non-persistent class is not supposed to be implemented in the ORM designer. Just add it in a separate code file. In general, you can also add custom code to the partial classes (YourClassName.vb) accompanying the ORM designer files (find more useful tips at ORM Data Model Designer and Wizard FAQ).

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.