Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
Please help on XamDataGrid add new record notification
posted

Hi support team,

we are struggling with XamDataGrid having the AddNew set to true (Add New Record is displayed on top of the grid allowing the user to start typing a new record) and binding to a custom BindingList. Please find the sample application attached.

 HowToGetNotifiedOnCollectionCommitEdit.zip

We have the requirement to first inject some of our domain objects to the constructor of a new view model and second do additional actions when the view model has been committed to the BindingList (user hits enter when typing the new record finished). The first requirement we achieve by implementing BindingList.AddNewCore. We also implement IList for other domain reasons so this is a requirement as well.

We weren’t successful with the second requirement. Please provide us help how we can get notified when the user hit enter and the view model has been committed to the BindingList. Consider that we don’t want to write Code-Bind for this. Additional information is provided in the attached solution.

  • 29990
    Verified Answer
    Offline posted

    Hello Tomas,

    I have been investigating into the sample project that you have provided, and at the moment, there does not exist a dedicated event that detects when the Add New Record actually commits. You might have noticed that when you begin typing in the AddNewRecord, your “Add” method will fire on your BindingList<ProductItemViewModel> in your sample project. This is because once you have typed a single character within the AddNewRecord, that is the moment that the data item is created and added to the underlying source collection. This is expected and intentional behavior, and this is also when the RecordAdded event of the XamDataGrid fires.

    In order to get the commit of the AddNewRecord, I would recommend doing something a bit more creative in this case. I am attaching a modified version of the sample project you sent that uses a Behavior<XamDataGrid> to handle the CellActivated, ExecutedCommand, and PreviewKeyDown events of the grid without use of code-behind.

    In the CellActivated event, the newly activated cell is checked for belonging to the AddNewRecord, and if it does, it sets a flag saying that the AddNewRecord is essentially “active.” In PreviewKeyDown, this flag is checked, as well as a check for whether or not the ActiveCell of the grid is in edit mode. The pressed key is checked for Enter, and the AddNewRecord’s DataItem property is checked for not null. This combination of events will commit the AddNewRecord. The ExecutedCommand event is a little extra here, but there is a command named “EndEditModeAndCommitRecord” that will fire as a result of the above, and so a flag is currently set in the PreviewKeyDown event if all of the other conditions remain true that is checked within the ExecuteCommand method.

    I hope this helps you. Please let me know if you have any other questions or concerns on this matter.

    6646.HowToGetNotifiedOnCollectionCommitEdit.zip