IndexAttribute Class

Specifies the target business class property's order index, that will be considered when generating layout items in a Detail View, and columns in a List View.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v18.1.dll

Declaration

[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public class IndexAttribute :
    ModelExportedValueAttribute,
    _Attribute
<AttributeUsage(AttributeTargets.Property, Inherited:=False, AllowMultiple:=False)>
Public Class IndexAttribute
    Inherits ModelExportedValueAttribute
    Implements _Attribute

Apply the Index attribute to business class properties, to specify the order by which they will be added to the property list used to arrange corresponding layout items in a Detail View, and columns in a List View. To set the required index, pass it as the attribute's index parameter. When generating the Application Model's nodes, the index specified via this attribute will be assigned to the appropriate BOModel | <Class> | OwnMembers | <Member> node's IModelNode.Index property.

The property list that is used to arrange corresponding layout items in a Detail View and columns in a List View is populated in the following way. First, the properties that are indexed via the Index attribute are added in index order. Then, non-indexed properties are added in a particular order. In a List View, only the properties that are declared in the represented class are made visible, and arranged according to their order in the list. The inherited properties are made invisible (their Index property in the Application Model's Views | <ListView> | Columns | <Column> node is set to -1). In a Detail View, the layout items corresponding to properties are grouped according to particular rules. These rules are fully detailed in the View Items Layout Customization topic. However, the order in which they follow in a group is determined by the order in which the corresponding properties are listed.

The following example demonstrates how the Index attribute influences the column order in a List View and the layout items order in a Detail View.

[DefaultClassOptions]
public class DomainObject1 : BaseObject {
    public DomainObject1(Session session) : base(session) { }
    [Index(1)]
    public int Property1 {
        get { return GetPropertyValue<int>("Property1"); }
        set { SetPropertyValue<int>("Property1", value); }
    }
    [Index(2)]
    public int Property2 {
        get { return GetPropertyValue<int>("Property2"); }
        set { SetPropertyValue<int>("Property2", value); }
    }
    [Index(3)]
    public int Property3 {
        get { return GetPropertyValue<int>("Property3"); }
        set { SetPropertyValue<int>("Property3", value); }
    }
    [Index(5)]
    public int Property4 {
        get { return GetPropertyValue<int>("Property4"); }
        set { SetPropertyValue<int>("Property4", value); }
    }
    [Index(4)]
    public int Property5 {
        get { return GetPropertyValue<int>("Property5"); }
        set { SetPropertyValue<int>("Property5", value); }
    }
}
[DefaultClassOptions]
public class DomainObject2 : DomainObject1 {
    public DomainObject2(Session session) : base(session) { }
    [Index(7)]
    public int Property6 {
        get { return GetPropertyValue<int>("Property6"); }
        set { SetPropertyValue<int>("Property6", value); }
    }
    [Index(6)]
    public int Property7 {
        get { return GetPropertyValue<int>("Property7"); }
        set { SetPropertyValue<int>("Property7", value); }
    }
    public int Property8 {
        get { return GetPropertyValue<int>("Property8"); }
        set { SetPropertyValue<int>("Property8", value); }
    }
}

In the Detail and List Views of the DomainObject1 class, properties are arranged according to the indexes specified for them:

IndexAttribute_DetailView1

IndexAttribute_ListView1

In the Detail View of the DomainObject2 class, inherited properties are grouped and arranged according to the indexes specified for them in the base class. The properties declared in the DomainObject2 class are combined in a separate group, within which they are arranged in the order they are added to the property list: first, indexed properties and then, non-indexed properties are displayed.

IndexAttribute_DetailView2

In the List View of the DomainObject2 class, properties follow each other according to the order they are added to the properties list: first, indexed properties and then, non-indexed properties are displayed. Inherited properties are made invisible.

IndexAttribute_ListView2

Since Property Editors are automatically grouped according to specific rules, apply the Index attribute in code when you are sure that the target properties will be contained in the same group. For instance, if you index an unlimited string within the properties that will be represented by simple editors, the memo editor representing this string will be located in a separate group, irrespective of the index you specified.

Inheritance

Object
Attribute
DevExpress.Persistent.Base.ModelExportedValueAttribute
IndexAttribute

See Also