This is a migrated thread and some comments may be shown as answers.

AddNewItem() returning false

5 Answers 71 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 04 Feb 2013, 07:03 PM
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?

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 05 Feb 2013, 08:01 AM
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.

0
Jeff
Top achievements
Rank 1
answered on 05 Feb 2013, 07:14 PM
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,
0
Maya
Telerik team
answered on 06 Feb 2013, 07:47 AM
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.

0
Jeff
Top achievements
Rank 1
answered on 06 Feb 2013, 03:32 PM
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.
0
Maya
Telerik team
answered on 07 Feb 2013, 08:22 AM
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.

Tags
DataForm
Asked by
Jeff
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or