Current filter:
                                You should refresh the page.

                                You are using an older version of the DevExpress Support Center.

                                  • I have the following classes

                                    [NavigationItem("Menu")] [DomainComponent] public class Customer : BasicBO { public Customer() { Invoices = new List<Invoice>(); } public string Name { get; set; } public virtual List<Invoice> Invoices { get; set; } } [DomainComponent] public class Invoice : BasicBO { public Invoice() { Lines = new List<InvoiceLine>(); } public virtual Customer Customer { get; set; } public virtual List<InvoiceLine> Lines { get; set; } } [DomainComponent] public class InvoiceLine : BasicBO { public string Description { get; set; } } public class BasicBO : IXafEntityObject { [Key] public int Id { get; set; } public void OnCreated() { } public void OnSaving() { } public void OnLoaded() { } }
                                    The Invoices display in a tab inside the customer detail view. When I try to add a new invoice the invoices detail view opens up, but the invoice customer is blank. How do I pre-initialise the invoice to have the currently selected customer?
                                • kirsten greed 09.14.2015

                                  Here is my demo project

                                • kirsten greed 09.14.2015

                                  Here is a screen cast of my problem
                                  I want the invoice record to be pre-initialised with the customer 'TEST'

                                • Andrew L (DevExpress Support) 09.14.2015

                                  Hi Kirsten,

                                  Thank you for the detailed information.  We need additional time to research it.  We will get back to you once we have any results or need extra information.  Your patience is appreciated.

                                1 Solution

                                Creation Date Importance Sort by

                                I was able to solve this using the NewObjectViewController

                                using DevExpress.Data.Filtering; using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using Solution1.Module.BusinessObjects; namespace Solution1.Module.Controllers { public partial class NewInvoiceController : ViewController { private object _focusedObject; private NewObjectViewController controller; public NewInvoiceController() { InitializeComponent(); } protected override void OnActivated() { base.OnActivated(); // Perform various tasks depending on the target Window. controller = Frame.GetController<NewObjectViewController>(); controller.ObjectCreated += controller_ObjectCreated; } private void controller_ObjectCreated(object sender, ObjectCreatedEventArgs e) { var detailView = ObjectSpace.Owner as DetailView; if (detailView == null) { return; } var customer = detailView.CurrentObject as Customer; if (customer != null) { var invoice = e.CreatedObject as Invoice; if (invoice != null) { var os = e.ObjectSpace; invoice.Customer = os.FindObject<Customer>(CriteriaOperator.Parse("[Id]=? ", customer.Id)); } } } } }
                                Show all comments
                                • Andrew L (DevExpress Support) 09.15.2015

                                  Hi Kirsten,

                                  Yes, you have found the correct solution for this problem and you can use it.
                                  But I suggest that you use the ObjectSpace.GetObject method to get an object from the right ObjectSpace. This method works faster.
                                  Here is my variant of a ViewController :

                                  using Solution1.Module.BusinessObjects; using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule;  namespace Solution1.Module.Controllers {     public class MyVC:ObjectViewController<ListView,Invoice> {         public MyVC() {             TargetViewNesting = Nesting.Nested;         }         protected override void OnActivated() {             base.OnActivated();             NewObjectViewController controller = this.Frame.GetController<NewObjectViewController>();             controller.ObjectCreated += controller_ObjectCreated;         }          void controller_ObjectCreated(object sender,ObjectCreatedEventArgs e) {             Customer _customer = ((NestedFrame)this.Frame).ViewItem.CurrentObject as Customer;             if(_customer != null)                 ((Invoice)e.CreatedObject).Customer = e.ObjectSpace.GetObject<Customer>(_customer);         }         protected override void OnDeactivated() {             NewObjectViewController controller = this.Frame.GetController<NewObjectViewController>();             controller.ObjectCreated -= controller_ObjectCreated;             base.OnDeactivated();         }     } }
                                • kirsten greed 09.15.2015

                                  Cool, I didn't know we could declare a controller with generics. Is that a new thing?

                                • kirsten greed 09.15.2015

                                  Also I am interested why you preferred not to have a module wide instance of controller.

                                • Andrew L (DevExpress Support) 09.16.2015

                                  Hi Kirsten,

                                  The generic ObjectViewController<ViewType, ObjectType> class is available for several years at least.
                                  The only restriction is that you need to create it in code rather than use a special ViewController template item in the gallery. But inheritance from this class allows you to avoid unnecessary casts to access to DetailView's or CurrentObject's specific properties.
                                  >Also I am interested why you preferred not to have a module wide instance of controller.
                                  I am afraid that I do not completely understand this question. Would you please clarify it in greater detail.

                                • kirsten greed 09.17.2015

                                  Now I realise I did not need to do any of this because XAF does it for me.  What it does not do is display the parent correctly in the child when the child record is created.  I will start a new ticket.

                                • Andrew L (DevExpress Support) 09.18.2015

                                  Hi Kirsten,

                                  Thank you for your feedback. Yes, I see that you raised a new ticket regarding this problem: child records not displaying header link correctly
                                  We will process this question in it.