Hi,
I'm having some problems retrieving the value of a cell in the CellExitedEditMode event using the AddNewRowFeature.
Value's of a cell that have a column which key is linked to a field in my business object on the first level are retrieved correctly (eg executorFullName below, e.Cell.Value contains a string) <igGrid:TextColumn IsSortable="False" IsFixed="Left" HeaderText="Executor" Key="executorFullName" />
However: values's of a cell that have a column which key is linked to a fied in my business object on the second level are not retrieved correctly (it is null)
<igGrid:TextColumn IsSortable="False" IsFixed="Left" HeaderText="Home Base" Key="oHomeBase.description" />
e.Cell.Value of oHomeBase.description is null.
Regular editing of existing records on my grid works perfectly. The above scenario only occurs when using AddNewRow.
Thank you for this post. I have been trying to figure out how to initialize the add new row values in the xamgrid and this works for me.
When the grid creates such new objects to use for its needs (such as for AddNewRow feature), it would fire the DataObjectRequested event. You can add an event handler for this event and supply your own "empty" object to use by returning it in e.NewObject event argument. This gives you the ability to do some custom initialization if needed. If you don't do that, then the grid will try to automatically create a new object for you.
So, you could add a listener for the DataObjectRequested event , create a new object there and set some initial values of its fields:
private void igGrid_DataObjectRequested(object sender, DataObjectCreationEventArgs e)
{
if (e.ObjectType == typeof(MyDataObject))
MyDataObject newObj = new MyDataObject();
newObj.oHomeBase = new HomeBase();
e.NewObject = newObj;
}
Hope that helps,
Something additional I can mention is that "oHomeBase" is of a type of a Linq-to-SQL class. I don't know how I can make that it doesn't initialise on null.
Hi Georgi,
I understand what you are saying.
Problem is that I don't know where the "MyDataObject" object is initialised when it is used on AddNewRow.
If I debug into CellExitedEditMode when placing values into cells of a new row, e.Cell.Value is indeed filled for properties of the object that are not initialised on null.
Are you sure your oHomeBase object is not null?
If you have fields in your business object, that represent some complex objects, you'll have to make sure they are not null when you're adding a new row using AddNewRow. To be more clear on that, I'll try to explain it this way:
Let's say your grid is bound to a list of objects of type "MyDataObject" and MyDataObject has a property, called "oHomeBase", which is of type "HomeBase". Now, let's say that "HomeBase" is a complex type which has a property , called "description". And, you bound one of the grid's columns to this "description" property with the syntax you described above.
So, when you add a new row, using the AddNewRow feature, it will create a new object of type MyDataObject for you, to add to the data source. But it's up to you to make sure that the "oHomeBase" property is not null, in order to set the "description" on it.
One way to hande this is to make this "oHomeBase" property read-only and handle it like this:
oHomeBase
get
if (this._oHomeBase == null)
this._oHomeBase = new HomeBase();
return this._oHomeBase;