Skip to main content
.NET 8.0+

ViewItem.CreateControl() Method

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

Namespace: DevExpress.ExpressApp.Editors

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

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.

See Also