How to: Specify a Display Member (for a Lookup Editor, Detail Form Caption, etc.)
- 2 minutes to read
Each business object used in an XAF application should have a default property. The default property value is treated as a human-readable identifier in an XAF application UI (e.g., FullName of a Contact, Subject of a Task, etc.). Default property values are displayed in the following:
- Detail View captions;
- the leftmost columns of List Views;
- Lookup List Views;
- Lookup Editors in an unexpanded state.
Default Property of a Business Class
It is strongly recommended that you apply the XafDefaultPropertyAttribute attribute and pass the default property name to this attribute. If you omit the XafDefaultProperty attribute, a GUID or Integer identifier may be displayed in the UI (this situation confuses end-users).
using DevExpress.ExpressApp.DC;
// ...
[XafDefaultProperty("Subject")]
public class Task {
// ...
public string Subject { get; set; }
// ...
}
Alternatively, you can use the DefaultProperty attribute from the System.ComponentModel namespace.
Tip
XAF can detect the default property automatically. If a property name is Name, or it includes the Name substring, then this property is considered default, and there is no need to specify the default property explicitly.
Property Displayed in a Lookup Editor
The default property of a referenced business object is displayed in a Lookup Property Editor. If you need to use another property in lookups, use the IModelCommonMemberViewItem.LookupProperty property in the Model Editor.