Skip to main content
Solved

Modify DropDown List Field dynamically

  • 15 December 2020
  • 5 replies
  • 1845 views

SadokHanini
Freshman II

Hello, 

I manage to create a custom filed and set it to dropdown list but only with static values 
code below : 

[PXDBInt]

[PXIntList(new int[] {0, 1, 2, 3}, new string[] {"North", "East", "South", "West"})]

[PXUIField(DisplayName="ListLibre1")]

 

I want to modify the dropdown list values dynamically and directly on the screen.

How it can be done ?

 

Thanks :) 

Best answer by Naveen Boga

Hello @SadokHanini 

 

To load the drop-down values dynamically, then we need to use fieldselecting event to load the values dynamically. Please find the example below. 

 


        protected virtual void SOOrder_UsrKNOrderReturnCodes_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            SOOrder row = e.Row as SOOrder;
            if (row != null)
            {
                List<string> allowedValues = new List<string>();

                foreach (KNAMICodes objAMICodes in PXSelect<KNAMICodes, Where<KNAMICodes.codeType, Equal<AMIConstants.ReturnCodes>,
                    And<KNAMICodes.isActive, Equal<True>>>>.Select(Base))
                {
                    allowedValues.Add(objAMICodes.Codecd);
                }
                e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 10, true, typeof(KNAMICodes.codecd).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedValues.ToArray(), false, null);
                ((PXStringState)e.ReturnState).MultiSelect = false;
            }
        }

 

I hope this will help you!!
 

View original
Did this topic help you find an answer to your question?

5 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • Answer
  • December 15, 2020

Hello @SadokHanini 

 

To load the drop-down values dynamically, then we need to use fieldselecting event to load the values dynamically. Please find the example below. 

 


        protected virtual void SOOrder_UsrKNOrderReturnCodes_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            SOOrder row = e.Row as SOOrder;
            if (row != null)
            {
                List<string> allowedValues = new List<string>();

                foreach (KNAMICodes objAMICodes in PXSelect<KNAMICodes, Where<KNAMICodes.codeType, Equal<AMIConstants.ReturnCodes>,
                    And<KNAMICodes.isActive, Equal<True>>>>.Select(Base))
                {
                    allowedValues.Add(objAMICodes.Codecd);
                }
                e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 10, true, typeof(KNAMICodes.codecd).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedValues.ToArray(), false, null);
                ((PXStringState)e.ReturnState).MultiSelect = false;
            }
        }

 

I hope this will help you!!
 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • December 15, 2020

darylbowman
Captain II
Forum|alt.badge.img+13
Naveen B wrote:

 

@Naveen B  This site is not responding


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • February 16, 2022

Joe Schmucker
Captain II
Forum|alt.badge.img+3

@Naveen Boga 

Since you are using allowedValues.ToArray() twice, does that mean that you are setting the value of the selected item in the DDL to the display value for each item?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings