I need to change the datatype of the selected cell to be able to use a custom editor. Is this possible?
Background:
My business objects have a lot of complex properties with lots of information about how to handle the real value itself. For these properties I have a custom editor I want to use for editing data in the datagrid.
For memory purposes I can't use a list of that complex datatype as grids datasource. So i build up a list with just the values as strings for rendering the records.
Entering editmode I extract the needed information from field label and reconstruct my business object. Now I want to use the complex property type as source for my custom editor.
Here is a modified HostAnyControl solution to for reproducing the problem in a smaller environment.
pointField.Settings.EditAsType = typeof(String);
But if I set the cell.value to data of ComplexDataType when EditModeStarting raises, the editor just gets the data casted to string and the values will not be used.
Setting the EditAsType to typeof(ComplexDataType) the field values of type string won't be shown in the fields column.
pointField.Settings.EditAsType = typeof(ComplexDataType);
For all reading an article from the beginning to the end before downloading anythif, here again the sources for the sample project:
Hope anyone can help....
Great job,
Thank you!
Uploading the working sample modified by Curtis.
Sam
We'll try to get a solution to this as soon as possible.
Hi,
thanks to your engineering!
But this solution has a problem with filtering.
Changing a value using the custom editor works fine.
Also the filter displays the edited value:
and uses it correctly:
But deleting the filter causes a reset of the displayed value:
Entering editmode again shows the right, last edited value.
It looks like there's a refetch for the grids datasource from a cached list.
Engineering came through and modified the sample to work with the concept of swapping the data when going to edit mode.
Engineering notes: instead of setting the EditAsType of the DataPoint UnboundField in Window1.xaml.cs, I changed it to set the EditorType to his ValueEditor derived editor of type ControlHostEditor. I then changed the ControlHostEditorStyle to set the EditTemplate and Template properties on the ControlHostEditor class (actually the properties are on the base ValueEditor class) instead of the other template properties that were defined on the ControlHostEditor (I removed those other template properties and also removed the Style he had for ControlHostEditor in generic.xaml)
I also modified the ComplexDataTypeEditor to update the DataPoint property of the ComplexDataType as its X and Y properties are updated. Note that this logic is not robust since it does not account for cancelling out of edit mode, but at least it demonstrates how to update the underlying complex data object.