Telerik RadGridView

Telerik RadGridView

Old forum URL: forums.lhotka.net/forums/t/6896.aspx


Code7 posted on Monday, May 04, 2009

Hi,

We are using the CSLA as our base framework and evaluating Telerik's Winform controls. Using Telerik's RadGridView control that is bound to a custom object, when trying to use the Grids add new row functionally we receive the following message:

System.MissingMethodException: Constructor on type ‘MyObject.whatever’ not found. At System.runtimeType.CreateInstanceimp(Binding…..

 

Since the object’s constructor is defined as private (using Class in-charge model) I can understand the error but not a solution. Any help greatly appreciated.

 

tetranz replied on Monday, May 04, 2009

I haven't used the Telerik grid but I think the problem will be solved if you override AddNewCore in the collection class.

protected override object AddNewCore()
{
      MyObject item = MyObject.NewMyObject();
      this.Add(item);
      return item;
}

That's the standard way if your objects don't have a public default constructor.

Tom_W replied on Tuesday, May 05, 2009

The only other thing worth noting on AddNewCore is that it's a parameterless method, so if your objects constructor doesn't have a zero parameter constructor you will need to either introduce one, or else set the mandatory values within AddNewCore, without passing the values into AddNewCore.

I only mention this as it tripped me up for a while and I thought it might save you some pain!

Code7 replied on Thursday, May 07, 2009

Excellent. Thanks for the info I will try the suggestions.

Code7 replied on Thursday, May 07, 2009

I overrode the AddNewCore method in the ObjectList which elimiated the error.  Now I have the Add New row displayed but where does one save the object back to the database? I have tried the RowChanging and RowChanged events but the New object is empty and the Grid Data is not available.

Any suggestion greatly appreciated.

Tom_W replied on Friday, May 08, 2009

Just as a double check:  In the grid can you edit and save changes to existing rows (i.e. existing custom business objects) correctly?  Are these changes persisted to the database?

Also are these child objects or root objects?  If they are child objects they you will need to invoke a save on the parent to get the data back to the database obviously.

Code7 replied on Friday, May 08, 2009

No, edits are not saved to the database nor the grid.  This is a root object that has no children.  Secondly I have since switched to binding the Telerik RadGridView to a BindingSource which is bound to the BO. Still no success.

Thanks for taking the time to respond.

Tom_W replied on Friday, May 08, 2009

Does it work correctly if you bind a standard Windows DataGridView to the bindingsource?

Couple of other questions: what exactly do you mean when you say 'edits are not saved to the grid'? Do you mean the underlying BO is not getting updated with the values from the grid (I.e. even before attempting the save)?

Also, how are you invoking the BO.Save() method, is there a save button on the form?

Code7 replied on Friday, May 08, 2009

Interesting....I thought of the same idea. I did not try the BO bound to a Windows DataGridView. I am in the process of testing that out. Be back in a moment.

 

Code7 replied on Friday, May 08, 2009

 I changed over to a Standard Windows DataGridview that is bound to a bindingsource that is bound to a BO. I have almost the same results so I must be missing the fundamentals.  

I set the datasource of the bindingsource to the BO in the forms load event:

boProducts= ieserv.Products.GetListOfProducts()

BOBindingSource=boProducts

All product information is disaplyed no issues.

In the Products Object I have the following:

Protected Overrides Function AddNewCore() As Object

Dim newProduct As ieServ.Products = ieSerrv.NewProduct()

Me.Add(newProductt)

Return newProduct

End Function

When I click the new row region of the DataGrid the AddNewCore method is called and I can enter values into the fields. Now when I move off the New Row, I was assumming that the bindingsource would take care of saving the results back to database but this is not the case. Although the DataGrid shows the newly added row since I did add the new Product Object to the list in the AddNewCore method.  Also when I move off the New Row, a second call is made and another empty row is added to the grid and the Product List (AddNewCore is called again).

Thanks again for your help.

 

Tom_W replied on Saturday, May 09, 2009

Hiya

OK, that helps narrow it down a bit, as you say it sounds like it's an issue with the objects rather than the grid control.

What type of object is boProjects?  Is it a standard Windows collection or a CSLA collection?  If it's a CSLA collection, which one is it (BusinessListBase, EditableRootListBase, etc?)


When I click the new row region of the DataGrid the AddNewCore method is called and I can enter values into the fields. Now when I move off the New Row, I was assumming that the bindingsource would take care of saving the results back to database but this is not the case.

For normal Windows or CSLA collections that isn't the default behaviour, you need to call an explicit save somewhere.  In CSLA if these objects are child to the parent collection then you can Save the parent and the children should save.  If the previous sentence is new to you then I would suggest you need to read Rocky's Expert 2008 Business Objects book before going any further with CSLA.

If you have read Expert 2008 BOs then I would suggest re-reading the stuff on Dynamic Editable Collection (page 190).  I haven't used these but they sound like they might be what you need if you don't want a save button on the form.

As a side note, and I'm sure you know this; in this instance the bindingsource is only a way of connecting the data in an object (e.g. product) or collection of objects (e.g. products) to the controls on your form.  A lot of what the binding source does is simply calling methods on your underlying objects using standard Windows binding interfaces. 

This is quite separate from the data access side of things (e.g. database CRUD) which would normally be initiated by your business objects and handled by your data layer.  In a lot of cases you would not want changes made on a grid to be immediately stored to the database (for example if you want to use n-level undo).


Also when I move off the New Row, a second call is made and another empty row is added to the grid and the Product List (AddNewCore is called again).


That's plain weird!  Can you trace where the two calls are coming from by looking at the call stack?

vbbojan replied on Saturday, May 09, 2009

Maybe you are missing AllowNew = True in the constructor of your Products object:

Private sub New()
  AllowNew = True
End Sub

Regards,
Bojan

Copyright (c) Marimer LLC