Ticket T541706
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Web - How to avoid issues with data-bound controls due to missing or non-unique key values

Unable to edit a newly created object in a nested collection

created 8 years ago

[DevExpress Support Team: CLONED FROM T539038: Assistance creating an efficient transaction entry screen in XAF web]
Hi Konstantin,

Thanks for all the assistance so far, I'm getting very close to the desired result.

Your suggestions have fixed the issues I had, but I have a new problem and an improvement I'd like to make:

  1. I experience an error when trying to delete a row on an unsaved order. See the attached video.

Thanks in advance,
Adam

Answers approved by DevExpress Support

created 8 years ago

This problem occurs because the newly created objects have no key property value assigned, and this makes a grid control behave the described way. To avoid this, consider changing the base class of the Record class and setting the BaseObject.OidInitializationMode Property value to OidInitializationMode.AfterConstruction. Alternatively, you can commit a master object after adding a child object. Let me know if you need further assistance.

    Show previous comments (1)
    DevExpress Support Team 8 years ago

      Please pardon my delayed response.
      The AutoGenerate property means that the key property value will be initialized by a database server when the object is being stored in the database. This means that uncommitted objects have the same default id. The ASPxGridView control requires objects to have unique keys to operate properly. Otherwise it will behave the way you described earlier. I have described possible solutions in my initial answer. Do not hesitate to contact us in case of further questions.

        Not a problem. I can't really change the base class (to use a Guid key), so I will need to go with the alternative approach (commit a master object after adding a child object). Do you have some documentation about the best practice to implement this?

        A A
        Arkady (DevExpress) 8 years ago

          Hello Adam,
          To commit a master object after adding a child object, you can use the following controller:

          C#
          using DevExpress.ExpressApp; using DevExpress.ExpressApp.Web.Editors.ASPx; namespace XafWebSample.Module.Web.Controllers { public class MasterObjectCommitController : ViewController<ListView> { protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); ASPxGridListEditor editor = View.Editor as ASPxGridListEditor; if(editor != null) { editor.Grid.RowInserting += (s, e) => { CompositeView parentView = ((NestedFrame)Frame).ViewItem.View; parentView.ObjectSpace.CommitChanges(); }; } } public MasterObjectCommitController() { this.TargetViewNesting = Nesting.Nested; } } }

          Thanks,
          Arkady

          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.