Skip to main content
A newer version of this page is available. .

Access Editor Settings

  • 7 minutes to read

This topic demonstrates how to access editors in a Detail View using a View Controller. This Controller searches the Contact Detail View for an Anniversary Property Editor that binds data to a control, and specifies that the control displays “N/A” when the Anniversary property value is not set. The “N/A” text is shown when the Detail View is in the Edit Mode (DetailView.ViewEditMode).

Note

We recommend reviewing the following topics before proceeding:

To see the example discussed in this topic, access the MainDemo.Module.Win | Controllers or MainDemo.Module.Web | Controllers folder and open the WinNullTextEditorController.cs (WinNullTextEditorController.vb) or WebNullTextEditorController.cs (WebNullTextEditorController.vb) file. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.1\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version of this demo is available online at https://demos.devexpress.com/XAF/MainDemo.

Access Editor Settings in a WinForms Application

  • Add a View Controller called “WinNullTextEditorController” to the MySolution.Module.Win project as described in the Add a Simple Action lesson (steps 1-3). Make sure you set the TargetViewType property to DetailView (step 3).

  • Override the OnActivated method. Use the CompositeView.FindItem method to get the Anniversary Property Editor from the current View’s CompositeView.Items list which contains Property Editors and View Items.

  • In the OnActivated method, subscribe to the CompositeView.ItemsChanged event. Then, the Controller processes the Anniversary View Item that a user added at runtime. Otherwise, the Controller works only with the item included in the Detail View at design time.
  • Use the ViewItem.Control property to access the Anniversary Property Editor’s control. Cast the control to the appropriate type to use its properties or subscribe to its events. See Data Types Supported by built-in Editors to determine the valid control type for a Property Editor. In the example below, the ViewItem.Control value is cast to the BaseEdit type.
  • Subscribe to the ViewItem.ControlCreated event and place your customization code in its handler to prohibit the control customization until the control is created.

The following code demonstrates the WinNullTextEditorController:

using DevExpress.XtraEditors;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Utils;
// ...
public partial class WinNullTextEditorController : ViewController {
    public WinNullTextEditorController() {
        InitializeComponent();
        RegisterActions(components);
    }
    private void InitNullText(PropertyEditor propertyEditor) {
        ((BaseEdit)propertyEditor.Control).Properties.NullText = CaptionHelper.NullValueText;
    }
    private void WinNullTextEditorController_ItemsChanged(Object sender, ViewItemsChangedEventArgs e) {
        if(e.ChangedType == ViewItemsChangedType.Added && e.Item.Id == "Anniversary") {
            TryInitializeAnniversaryItem();
        }
    }
    private void propertyEditor_ControlCreated(Object sender, EventArgs e) {
        InitNullText((PropertyEditor)sender);
    }
    protected override void OnActivated() {
        base.OnActivated();
        ((CompositeView)View).ItemsChanged += WinNullTextEditorController_ItemsChanged;
        TryInitializeAnniversaryItem();
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        ((CompositeView)View).ItemsChanged -= WinNullTextEditorController_ItemsChanged;
    }
    public void TryInitializeAnniversaryItem() {
        PropertyEditor propertyEditor = ((DetailView)View).FindItem("Anniversary") as PropertyEditor;
        if(propertyEditor != null) {
            if(propertyEditor.Control != null) {
                InitNullText(propertyEditor);
            }
            else {
                propertyEditor.ControlCreated += new EventHandler<EventArgs>(propertyEditor_ControlCreated);
            }
        }
    }
}

Note that the WinNullTextEditorController uses the CaptionHelper.NullValueText property to get a localized “N/A” text.

Run the WinForms application and open the Contact Detail View. The Anniversary editor shows the “N/A” text if the editor’s value is unspecified.

Tutorial_EF_Lesson8_1

Tip

This approach is not applicable to List View’s in-place editors. To customize these editors, do one of the following:

Access Editor Settings in an ASP.NET Application

The following code demonstrates the WebNullTextEditorController:

using DevExpress.Web;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Web.Editors;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Editors;
// ...
public partial class WebNullTextEditorController : ViewController {
    public WebNullTextEditorController() {
        InitializeComponent();
        RegisterActions(components);
    }
    private void InitNullText(WebPropertyEditor propertyEditor) {
        if(propertyEditor.ViewEditMode == DevExpress.ExpressApp.Editors.ViewEditMode.Edit) {
            ((ASPxDateEdit)propertyEditor.Editor).NullText = CaptionHelper.NullValueText;
        }
    }
    private void propertyEditor_ControlCreated(object sender, EventArgs e) {
        InitNullText((WebPropertyEditor)sender);
    }
    protected override void OnActivated() {
        base.OnActivated();
        WebPropertyEditor propertyEditor = ((DetailView)View).FindItem("Anniversary") as WebPropertyEditor;
        if(propertyEditor != null) {
            if(propertyEditor.Control != null) {
                InitNullText(propertyEditor);
            }
            else {
                propertyEditor.ControlCreated += new EventHandler<EventArgs>(propertyEditor_ControlCreated);
            }
        }
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        ViewItem propertyEditor = ((DetailView)View).FindItem("Anniversary");
        if(propertyEditor != null) {
            propertyEditor.ControlCreated -= new EventHandler<EventArgs>(propertyEditor_ControlCreated);
        }
    }
}

Note that the WebNullTextEditorController uses the CaptionHelper.NullValueText property to get a localized “N/A” text.

Run the ASP.NET application and open the Contact Detail View. The Anniversary editor shows the “N/A” text if the editor’s value is unspecified.

Tutorial_EF_Lesson8_3

Tip

This approach does not affect List View’s in-place editors. To customize these editors as well, use the solution described in the How to: Customize a Built-in Property Editor (ASP.NET) topic. Alternatively, access the required in-place Web List Editor as directed in the ComplexWebListEditor.FindPropertyEditor method description. To apply custom settings to an ASPxGridListEditor‘s column, handle the ASPxGridListEditor.CreateCustomGridViewDataColumn and ASPxGridListEditor.CustomizeGridViewDataColumn events. If you need to access a template for displaying cells within the current column, use the ASPxGridListEditor.CreateCustomDataItemTemplate and ASPxGridListEditor.CreateCustomEditItemTemplate events.

Due to WinForms and ASP.NET platform specifics, View Item and List Editor controls may not be immediately ready for customization after the control is created. Consider handling additional platform-dependent events or using alternative approaches if the customizations above do not have any effect.

These additional platform-dependent events indicate the controls’ “ready” state: a control has been added to the form controls hierarchy or has been bound to data. Contact us using the Support Center if you need additional help to perform customizations.

 

Next Lesson: Access Grid Control Properties

See Also