Ticket Q305425
Visible to All Users

How to populate single choice action's Items collection

created 14 years ago

I have an object, Customer, that has a column CustomerId. I would like to have a single choice action list that is populated with all the CustomerId's from the database.
What is the best way to populate a single choice action, dynamically, with the values from a particular column of an object?
Thanks,
Chris

Answers

created 14 years ago

Hello, Chris.
I believe the controller below does exactly what you want:

C#
public partial class CustomersController : ViewController { SingleChoiceAction customersAction; const string refreshItemId = "refersh"; public CustomersController() { InitializeComponent(); RegisterActions(components); customersAction = new SingleChoiceAction(this, "Customers", PredefinedCategory.RecordsNavigation); customersAction.Caption = "Customers"; customersAction.ItemType = SingleChoiceActionItemType.ItemIsOperation; customersAction.Execute += customersAction_Execute; } protected override void OnActivated() { base.OnActivated(); PopulateItemsCollection(); } void PopulateItemsCollection() { customersAction.Items.Clear(); customersAction.Items.Add(new ChoiceActionItem(refreshItemId, "Refresh Customers", null)); List<SortProperty> sortProperties = new List<SortProperty>(); sortProperties.Add(new SortProperty("CustomerId", SortingDirection.Ascending)); foreach (Customer customer in View.ObjectSpace.CreateCollection(typeof(Customer), null, sortProperties)) { string itemCaption = CaptionHelper.GetMemberCaption( typeof(Customer), "CustomerId") + " :" + customer.CustomerId; customersAction.Items.Add( new ChoiceActionItem(customer.CustomerId, itemCaption, customer)); } } void customersAction_Execute(object sender, SingleChoiceActionExecuteEventArgs e) { if (e.SelectedChoiceActionItem.Id == refreshItemId) { PopulateItemsCollection(); } else { IObjectSpace objectSpace = Application.CreateObjectSpace(); Customer customer = objectSpace.GetObject(e.SelectedChoiceActionItem.Data as Customer); e.ShowViewParameters.CreatedView = Application.CreateDetailView(objectSpace, customer); } } }

The PopulateItemsCollection method adds all Customer objects to the action's Items collection. The supplementary "Refresh Customers" item is intended for manual refreshing. If it is required to filter the Customer objects displayed as the Action's items, pass the corresponding criteria as the second parameter of the ObjectSpace.CreateCollection method. If you need additional assistance, let me know.
Thanks,
Konstantin B

    Show previous comments (1)
    S S
    sri charan kadari 9 years ago

      Is there any way to select all CustomerID's at a time.?

      DevExpress Support Team 9 years ago

        In this scenario, use PopupWindowChoiceAction instead of SingleChoiceAction. In the popup window, the Customer List View can be displayed. An example is provided in the Add an Action that Displays a Pop-up Window tutorial.

        S S
        sri charan kadari 9 years ago

          Thanks Konstantin.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.