Skip to main content
.NET 6.0+

ViewItem.CreateControl() Method

Creates a control that represents the current View Item in a UI.

Namespace: DevExpress.ExpressApp.Editors

Assembly: DevExpress.ExpressApp.v22.1.dll

Declaration

public void CreateControl()

Remarks

This method is automatically called by the Detail View (see ViewItem.View) when the detail form is created. So, you do not have to call it manually.

When implementing a descendant of the ViewItem class, override the CreateControlCore method to create the required control (Windows Forms or ASP.NET Web Forms). This method is called by the CreateControl method.

public class MyViewItem : ViewItem {
   protected override object CreateControlCore() {
      DevExpress.XtraEditors.LabelControl result = new DevExpress.XtraEditors.LabelControl();
      result.Dock = DockStyle.Fill;
      result.Text = Info.GetAttributeValue("Text");
      result.AutoSizeMode = LabelAutoSizeMode.Vertical;
      return result;
   }
}

To access the control returned by the Control property, use the ViewItem.Control property. If you need to execute a custom action when this control is created, handle the ViewItem.ControlCreating and/or ViewItem.ControlCreated event(s).

By default, View Item controls are initialized immediately, when a View is created. This behavior ensures that you can rely on the View.ControlsCreated and ViewController.ViewControlsCreated events when accessing a View Item’s control. The downside is that this behavior is slower. You can change this behavior to speed up creation of complex Views, by setting the XafApplication.DelayedViewItemsInitialization property to true. This will ensure that View Items’ controls are initialized only when they are visible to end-users. However, in this instance you can no longer rely on the View.ControlsCreated and ViewController.ViewControlsCreated events alone, and should additionally ensure that your code is not accessing View Items’ controls before they are created. For additional information, refer to the XafApplication.DelayedViewItemsInitialization property description.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreateControl() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also