KB Article K18435
Visible to All Users

How to serialize a custom property of the DevExpress control's descendant

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

Comments (2)

    Hello, I am using a WPF application and devexpress v 18.2.7
    I have adding this Mask to My Grid Column like this:

    C#
    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 :

    XML
    <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.

    Nadezhda (DevExpress Support) 6 years ago

      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.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.