Skip to main content
.NET 8.0+

View.AllowNew Property

Provides access to a collection of reason/value pairs used to allow or prohibit creation of new objects via a View.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public BoolList AllowNew { get; }

Property Value

Type Description
BoolList

A BoolList object that represents a collection of key/value elements.

Remarks

There can be various reasons to allow or prohibit creation of new objects via a View. So, a View has the AllowNew collection, whose elements represent a pair of string and Boolean values. The string value specifies a reason and the Boolean value specifies whether to allow creation of new objects. New objects cannot be created if at least one of the AllowNew collection elements contains a false value.

When creation of new objects is prohibited, the New Action is not available. To determine whether object creation is allowed for a View, use the AllowNew property in a conditional expression. Alternatively, use the BoolList.ResultValue property of the object returned by AllowNew.

View myView;
//...
BoolList creatableList = myView.AllowNew;
if (creatableList) {
    //...
}

To prohibit creation of new objects, use the BoolList.SetItemValue method of the BoolList object returned by this property. Pass the prohibition reason as the first parameter, and false, or a Boolean expression as the second parameter. Alternatively, you can use the [key] operator of the BoolList object returned by the AllowNew property, to get or set the specified key’s value.

View myView;
//...
BoolList creatableList = myView.AllowNew;
creatableList["myKey"] = false;

To allow new objects to be created, use the BoolList.RemoveItem method of the BoolList object returned by this property. Pass the key (reason) of the item with the false value. Call this method as many times as there are items with the false value. Alternatively, you can call the BoolList.SetItemValue method by passing the key, which has false as a value, and true as a new value for it.

View myView;
//...
BoolList creatableList = myView.AllowNew;
creatableList["disablingKey"] = true;
public class MyController : ViewController {
   private void UpdateViewStateEventHandler(object sender, EventArgs e) {
      View.AllowNew.SetItemValue("CurrentUser", SecuritySystem.CurrentUser.FirstName == "Sam");
   }
   protected override void OnActivated() {
      base.OnActivated();
      View.CurrentObjectChanged += UpdateViewStateEventHandler;
   }
}

When a View’s AllowNew state is changed, the View.AllowNewChanged event is raised.

See Also