SingleChoiceAction.Execute Event
Occurs when an end-user clicks the required item located in the Single Choice Action’s item list.
Namespace: DevExpress.ExpressApp.Actions
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Event Data
The Execute event's data class is SingleChoiceActionExecuteEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Action | Provides access to the Action being executed. Inherited from ActionBaseEventArgs. |
CurrentObject | Provides access to the current object represented by the currently displayed View. Inherited from SimpleActionExecuteEventArgs. |
SelectedChoiceActionItem | Provides access to a Single Choice Action’s selected item. |
SelectedObjects | Provides access to the objects selected in the currently invoked View. Inherited from SimpleActionExecuteEventArgs. |
ShowViewParameters | Provides access to the ShowViewParameters object, specifying a View, displayed after executing the current Action. Inherited from ActionBaseEventArgs. |
Remarks
Handle this event to execute custom code when an end-user clicks an item located in the current Single Choice Action’s item list (see ChoiceActionBase.Items). To access this item, use the handler’s SingleChoiceActionExecuteEventArgs.SelectedChoiceActionItem parameter. If you need an additional View to be displayed after executing the Action, use the ActionBaseEventArgs.ShowViewParameters parameter to specify this View and its settings.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
namespace YourSolution.Module.Controllers;
public class CustomBlazorController : ViewController {
public CustomBlazorController() {
var mySingleChoiceAction1 = new SingleChoiceAction(this, "MySingleChoiceAction", null);
mySingleChoiceAction1.Items.Add(new ChoiceActionItem("Caption1", "Test1"));
mySingleChoiceAction1.Items.Add(new ChoiceActionItem("Caption2", "Test2"));
mySingleChoiceAction1.Execute += MySingleChoiceAction1_Execute;
}
private void MySingleChoiceAction1_Execute(object sender, SingleChoiceActionExecuteEventArgs e) {
var selectedValue = e.SelectedChoiceActionItem.Data.ToString();
switch(selectedValue) {
case "Test1":
//your code
break;
case "Test2":
//your code
break;
}
}
}
For additional information, refer to the How to: Access Objects Selected in the Current View help topic.
Execute Actions Programmatically
We do not recommend that you use the DoExecute
and other methods to execute Actions because such methods can contain UI-specific code. You can refactor your Action’s event handlers and extract the required code into separate methods. Call these separate methods directly without triggering UI-related Action code.
Programmatic execution of custom and built-in Actions is acceptable in rare advanced scenarios, for example, if you:
- Create a custom Action Container and call the
DoExecute
method inside the Action control. In this context, you have complete control over your custom code and can execute any action. Remember to trigger life-cycle events for your actions (such asExecute
). - Add new ways to invoke Actions from the UI (for example, support keyboard or voice control).
- Reuse a built-in Action in a specific context where you would need to write a lot of code to re-implement the Action’s internal business logic.
For more information on how to implement such complex requirements, refer to the following materials:
- XAF - How to execute Actions programmatically.
- “Related GitHub Examples” section of the SimpleAction.DoExecute topic.
- “Related GitHub Examples” section of the ParametrizedAction.DoExecute(Object) topic.