Configuration of Drop-Down Lists

You use drop-down controls to give users the ability to select a value from the list of predefined values.

Definition of a Drop-Down List

To configure a drop-down list, you use the PXStringList or PXIntList attribute in the definition of the data field in the data access class (DAC), as shown in bold type in the following example.

[PXDBString(1)]
[PXDefault(ShipmentStatus.OnHold)]
[PXUIField(DisplayName = "Status")]
[PXStringList(
    new string[]
    {
        ShipmentStatus.OnHold, ShipmentStatus.Shipping,
        ShipmentStatus.Cancelled, ShipmentStatus.Delivered
    },
    new string[]
    {
        "On Hold", "Shipping", "Cancelled", "Delivered"
    })]
public virtual string Status
{
    get;
    set;
}
Note: You use PXStringList when the values that are assigned to the field are strings, and you use PXIntList when the values are integers.

In this example, ShipmentStatus is an enumeration defined in the following way.

public static class ShipmentStatus
{
    public const string OnHold = "H";
    public const string Shipping = "S";
    public const string Cancelled = "C";
    public const string Delivered = "D";
}

As parameters, you provide two arrays of strings:

  • The array of values assigned to the field and saved to the database with the data record
  • The array of labels displayed in the user interface

Modifying a Drop-Down List at Run Time

You can modify a drop-down list at runtime by using the SetList<>() static method of the PXStringList attribute. You can do this in the RowSelected event handler or graph constructor.

The following code example shows the use of the SetList<>() method.

PXStringListAttribute.SetList<Shipment.status>(
    sender, row,
    new string[]
    {
        ShipmentStatus.OnHold,
        ShipmentStatus.Shipping,
    },
    new string[]
    {
        "On Hold",
        "Shipping",
    });

This code sets a new list of values and labels for the Status field.

In the type parameter, you specify the data field associated with the control. You also provide the cache object, the data record that will be affected by the method, the list of values, and the list of labels.

If the list of possible values of a drop-down control is changed dynamically at runtime, you should use the RowSelected event handler to manage the list. Otherwise, we recommend that you create the list in the graph constructor.

Insertion of a Not-Listed Value

If a drop-down list is configured with the PXStringList attribute, you can allow a user to enter values that are not options in the list. You do this by setting the AllowEdit property of the PXDropDown control to True on the ASPX page (see the setting in bold type in the following code).

<px:PXDropDown ID="edStatus" runat="server" DataField="Status"
               AllowEdit="True">
</px:PXDropDown>

Selection of Multiple Values

By default, a user can select one value from a drop-down list. The user will be able to select multiple values if you do all of the following:
  • Set the AllowMultiSelect property of the PXDropDown control to True on the ASPX page (see the setting in bold type in the following code).

    <px:PXDropDown ID="edStatus" runat="server" DataField="Status"
                   AllowMultiSelect="True">
    </px:PXDropDown>

    The selected values are displayed in the control separated by a semicolon.

  • Set the MultiSelect property of the PXStringList attribute to true, as shown in the following code.
    [PXString(20)]
    [PXUIField(DisplayName = "Priority")]
    [PXStringList(
        new string[]
        {
        WorkOrderPriorityConstants.High,
        WorkOrderPriorityConstants.Medium,
        WorkOrderPriorityConstants.Low
        },
        new string[]
        {
        Messages.High,
        Messages.Medium,
        Messages.Low
        },
        MultiSelect = true)]
    public virtual string Priority { get; set; }

The selected values are displayed in the control separated by a semicolon.