Description:
I have defined a custom property in the GridView descendant. How to save its value when the XtraGrid layout is saved?
Answer:
Properties of several DevExpress controls can be saved and restored via the SaveLayoutTo… and RestoreLayoutTo… methods (see Saving and Restoring Layout Basics). Serialization is performed by the XtraSerializer class. This class serializes properties marked with the XtraSerializableProperty attribute. Here are specifics of this attribute usage:
- If the property has a simple type, such as int or string, it is enough to apply this attribute without parameters.
- If the property has a complex type (a reference to an object), the XtraSerializableProperty attribute should be applied with the XtraSerializationVisibility.Content parameter to properly serialize a referenced object's content. Properties of the reference type should be marked with the XtraSerializableProperty attribute as well.
- If the property is a collection, the XtraSerializableProperty attribute should be applied with the XtraSerializationVisibility.Collection parameter. It will allow serializing the collection items properly. If it is required to recreate removed collection items when the layout is restored, the useCreateItem parameter of the XtraSerializableProperty attribute should be set to true. It is also required to define how new collection items should be created. To do it, implement the IXtraSupportDeserializeCollectionItem interface in the serialized class.
You can find a sample on how to use the XtraSerializableProperty attribute and implement the IXtraSupportDeserializeCollectionItem interface in the How to save and restore custom properties, defined in the PivotGridControl descendant, together with its layout Code Central example.
See also:
How to implement your own serializable property for the GridColumn
Hello, I am using a WPF application and devexpress v 18.2.7
I have adding this Mask to My Grid Column like this:
MyColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; MyColumn..EditSettings = new TextEditSettings() { Mask = "E2" };
I want to save the Mask of the GridColumn in the xml profile
the result seems to be like :
<property name="Item2" isnull="true" iskey="true"> <property name="GridRow">0</property> <property name="FieldName">BaseValue</property> <property name="VisibleIndex">1</property> <property name="ActualWidth">120</property> <property name="Mask">E2</property> </property>
Any suggestion please ?
Thank you.
Hello,
I've created a separate ticket on your behalf (How to serialize the Mask property). It has been placed in our processing queue and will be answered shortly.