RadDataForm bound to data with Collection

13 posts, 2 answers
  1. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 02 Jul 2014 Link to this post

    RadDataForm is really nice when binding to data with simple properties (int, string, bool, ...) but now I stuck while binding it to an entity type which has a collection of entities from another type. Let's assume there is a class Category with Fields ID (of type int) and Name (of type string) but also a property of type List<Product>.

    I use a RadListBox with a custom DataTemplate to show the products (inside RadDataForm EditTemplate) but when I edit values of a product the RadDataForm does not recognize that changes as it only checks for edits at the bound object (which is the Category but not the related products). Is this possible with RadDataForm? How can I tell my RadDataForm (manually) that the CurrentItem has changed?
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 07 Jul 2014 Link to this post

    Hi,

    You seem to have quite a complex scenario. Would it be possible for you to open a support ticket and send us a sample dummy project that illustrates it, so that we can debug it and research for a possible solution?

    Regards,
    Ivan Ivanov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 08 Jul 2014 Link to this post

    I don't think that this is quite a complex scenario so maybe my post was written too complex. Please take a look at your WPF DataForm "FirstLook" demo as an example. Imagine an employee has not just a name and a phone number but also a list of courses he has visited. How would you display this courses list within RadDataForm?

    What I try to achieve is displaying a list of objects with a RadListBox inside a RadDataForm with Add/Edit/Delete option for the list data. RadDataForm then should recognize about changes inside that list like it's getting noticed about changes in its DataFormDataFields.
  5. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 11 Jul 2014 Link to this post

    Hello,

    Thank you for the clarifications. Basically, RadDataForm is notified only for PropertyChanged of its current item. I guess that you need to notify the DataForm of these changes in order to enable the Cancel operation, to revert changes on some of the items of the nested collection property, am I right? You can try implementing IEditableObject, on the CurrentItem type. Thus you will have the Cancel command to be always enabled and when the Cancel button gets clicked the IEditableObject.CancelEdit implementation will be invoked.

    Regards,
    Ivan Ivanov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  6. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 14 Jul 2014 in reply to Ivan Ivanov Link to this post

    Thanks for your answer. I've now implemented IEditableObject to "track" changes on my bound item. In IEditableObject.CancelEdit I call CancelEdit for each child item that is displayed in the RadListBox so everything gets reset when the cancel button is clicked.

    Personally I think this is a common scenario because in most cases entities have relations to other entites so I think you should add such an example to your RadDataForm documentation. Again thanks for your answer, it helped a lot at solving my problem.
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 17 Jul 2014 Link to this post

    Hi,

    I am glad to hear that you have managed to solve this problem. We will address this scenario in our documentation.

    Regards,
    Ivan Ivanov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  8. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 30 Jan 2015 Link to this post

    Hi guys,
    Now I have exactly the same requirements. It seems that i need to start from scratch. Any documentation udpates about the scenario?
  9. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 30 Jan 2015 in reply to Johannes Link to this post

    Hi Jonannes,

    Could you be kind enough to tell me how to do that? or share me a piece of codes? Thanks a lot!
  10. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 02 Feb 2015 in reply to Jackey Link to this post

    Hello Jingfei,

    I implemented IEditableObject like Ivan suggested and added a private list to track the related items in each ViewModel class. So when RadDataForm changes to Edit Mode every Property value gets backuped - and also the mentioned list. I've created a popup window where users can select the related items they want and when that window closes every selected item is added to the list. If user hits Cancel then just restore the old list state. If user hits Commit you can compare the lists current state with the old one and add/delete the corresponding relations.
  11. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 02 Feb 2015 Link to this post

    Hello guys,

    Johannes, thanks a ton for sharing your experience! I am writing to add that we have a working online demo with IEditableObject. You can find it on demos > DataForm > FirstLook.

    Regards,
    Ivan Ivanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 08 Feb 2015 in reply to Ivan Ivanov Link to this post

    Hi Ivan,
    Thanks for your direction. I've implemented the IEditableObject interface, however, i found the method of CancelEdit would be called twice when i clicked the 'cancel' button on RadDataForm. This requires my code of that method to be idempotence, which is also a little hard for me to do that. I want to know the reason behind the ​twice​ or something i did wrong.

    Best wishes,
    J
  13. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 11 Feb 2015 in reply to Jackey Link to this post

    If I remember correctly at MSDN you can find WHY this is executed more than once. However it's important to know THAT it can be executed many times and we have to deal with that. At MSDN they just use a simple bool value like this:

    public class ExampleDataItemViewModel : IEditableObject
    {
        private bool _isInEditMode;
        private readonly EditableData _editableData;
     
        public ExampleDataItemViewModel()
        {
            _isInEditMode = false;
            _editableData = new EditableData();
        }
     
        // Properties, Events, Methods, ...
     
        #region Implementation of IEditableObject
     
        public void BeginEdit()
        {
            if (_isInEditMode == false)
            {
                _editableData.Value1 = Value1;
                _editableData.Value2 = Value2;
                _editableData.Value3 = Value3;
                // ...
                         
                _isInEditMode = true;
            }
        }
     
        public void CancelEdit()
        {
            if (_isInEditMode)
            {
                Value1 = _editableData.Value1;
                Value2 = _editableData.Value2;
                Value3 = _editableData.Value3;
                // ...
     
                _isInEditMode = false;
            }
        }
     
        public void EndEdit()
        {
            _isInEditMode = false;
        }
     
        #endregion
     
    }
  14. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 11 Apr 2015 in reply to Johannes Link to this post

    Thanks a lot for your help, Johannes.
Back to Top
UI for WPF is Visual Studio 2017 Ready