AddNewItem() returning false

6 posts, 0 answers
  1. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 04 Feb 2013 Link to this post

    I have a user control with a RadDataForm. It has a button that is bound to a command that calls radDataForm.AddNewItem().

    I'm using the control in two places. In one of them things are working fine. In the other, AddNewItem() is returning false.

    Clearly I am doing something wrong, but I'm having the hardest time figuring out what.

    Is there anyplace I could look to figure out exactly why AddNewItem() is deciding not to add a new item?  Is there some way of turning on some sort of logging trace?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 05 Feb 2013 Link to this post

    Hi Jeffrey,

    Generally, the ability to add and remove items depends on your source collection and the implementation of your business object. You need to have data source that you can insert new items into - like List, ObservableCollection, etc. and you need to have a default constructor in the implementation of your business object. Will it be possible to check whether those criteria are met ? 

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 05 Feb 2013 Link to this post

    Generally, the control will decide whether or not to allow users to add or remove items based on any number of things. The problem is that it doesn't seem to provide any information on what, in particular, is the reason for any specific case.

    Like I said, this control is allowing new items in one place where it is used, it is not in another. My guess is that I simply have it bound to the wrong object. When I get done with dealing with today's crisis, I'll be adding a do-nothing IValueConverter, so I can add a breakpoint in the debugger and see exactly what is being bound.

    Still, in general, I think it would be a good idea if the Telerik controls would report, via Visual Studio's debugging and tracing mechanisms, something about why it is deciding to do certain things.

    A message like "AddNewItem() failed because object foo does not support bar" would go a long way towards figuring out these sorts of problems,
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Feb 2013 Link to this post

    Hello Jeffrey,

    Actually, it is a bit beyond the functionality of the control to throw exceptions about its underlying collections and business objects (in case it is for validation). The ability to insert and remove items is not directly provided by the control - it actually counts on the source and the business object for doing so. Will it be possible to test the case where you cannot add new item with another control - RadGridView, DataGrid, ListBox, etc. in order to verify whether the problem is with RadDataForm and not with the source ?  

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 06 Feb 2013 Link to this post

    The problem was simply that I wasn't binding to the object that I thought I was, which became obvious once I installed a pass-through IValueConverter, and could see exactly what I was binding to.

    But as for the providing of an error trace - I understand that it's the collection that is responsible for adding and removing items. But AddNewItem() isn't throwing an exception, it's returning false. That means it's either using reflection to determine whether ItemsSource has an Add() method, or it's trying to call Add(), getting an exception and throwing it away, or both. It is the ItemsSource object that is responsible for adding new items to the collection, but it's AddNewItem() that is telling it to do so, and it's AddNewItem() that knows that it failed. And whatever information AddNewItem() has about that failure is being thrown away.

    And that information, if provided to the developer, through VS's DEBUG and TRACE capabilities, would make it easier to understand what is failing, when things aren't hooked up correctly.
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Feb 2013 Link to this post

    Hi Jeffrey,

    Thank you for the feedback. We will check out to see whether this behavior could be improved.  

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready