Skip to main content
.NET Framework 4.5.2+

SingleChoiceAction Class

Represents a Single Choice Action.

Namespace: DevExpress.ExpressApp.Actions

Assembly: DevExpress.ExpressApp.v24.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

[ToolboxTabName("DX.24.1: XAF Actions")]
public class SingleChoiceAction :
    ChoiceActionBase

Remarks

The SingleChoiceAction class inherits both the basic functionality of Actions from the ActionBase class, and the functionality of Choice Actions - from the ChoiceActionBase class.

Single Choice Actions are used to execute custom code when a user selects an item from the ChoiceActionBase.Items collection. You can populate this collection at design time via the Properties window. Select the Items property and click the ellipsis button provided for it. In the invoked ChoiceActionItems Collection Editor, add items and specify their settings.

Each item within the ChoiceActionBase.Items collection can contain child items as well. So, you can form a tree of items for a Single Choice Action.

Action Option Selection in XAF ASP.NET Core Blazor List View, DevExpress

You can specify the type of a Single Choice Action’s items: they can represent either modes or operations. To do this, use the SingleChoiceAction.ItemType property.

Add a Single Choice Action

You can add a Single Choice Action to a Controller inthe following ways:

  • In design time (for the .NET Framework projects): drag and drop the SingleChoiceAction item from the Toolbox (the XAF Actions section) onto the Controller’s Designer area.
  • In code: see the Add an Action with Option Selection (.NET) tutorial.

Note

CodeRush allows you to add Actions and Controllers with a few keystrokes. To learn about the Code Templates for XAF, refer to the following help topic: XAF Templates.

Run Custom Code in Single Choice Actions

To provide custom code to be executed when users select a single item within the Items collection, handle the SingleChoiceAction.Execute event. To access the selected item, use the handler’s SingleChoiceActionExecuteEventArgs.SelectedChoiceActionItem parameter.

Set the IModelActionWeb.IsPostBackRequired property to true to send a postback when a user executes an Action in an ASP.NET Web Forms application. For example, for Actions that download files or change the application’s language.

Example

The code sample below demonstrates how to implement a single choice action that allows users to filter a current list view.

The single choice action’s items (of the Department type) are retrieved from a data source. When a single choice action item is selected, the current list view displays employees assigned to the selected department.

using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using MainDemo.Module.BusinessObjects;

namespace MainDemo.Module {
    public class DepartmentFilterController : ObjectViewController<ListView, Employee> {
        SingleChoiceAction departmentFilterAction;
        public DepartmentFilterController() {
            departmentFilterAction = new SingleChoiceAction(this, "DepartmentFilter", "Filters");
            departmentFilterAction.Caption = "Department";
            departmentFilterAction.Execute += departmentFilterAction_Execute;
        }
        protected override void OnActivated() {
            base.OnActivated();
            departmentFilterAction.Items.Clear();
            foreach (Department department in ObjectSpace.GetObjects<Department>()) {
                departmentFilterAction.Items.Add(new ChoiceActionItem(department.Title, department.Oid));
            }
        }
        void departmentFilterAction_Execute(object sender, SingleChoiceActionExecuteEventArgs e) {
            View.CollectionSource.Criteria["DepartmentFilter"] = new BinaryOperator("Department.Oid", e.SelectedChoiceActionItem.Data);
        }
    }
}

Implements

See Also