function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Varshitha KVarshitha K 

How to add values selected in a picklist(multiselect) to another picklist?

Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Varshitha k

You want to do it through VF page or on Record detail page .

If it is VF page then how do you refer your picklist 
  1. inputField
  2. selectOption

In 2nd case you can manipulate using selectOption class methods.

If it is on detail page ,then you can use Apex trigger .

BTW Could you explain business case for same ?

 
ManojjenaManojjena
Hi Varshitha,
Please check below link it may solve your problem .
https://hisrinu.wordpress.com/2011/05/30/custom-multi-select-picklist-field-in-visualforce/


 
Varshitha KVarshitha K
@Ashish:Can you explain me with a sample code?
Varshitha KVarshitha K
@Ashish:I want using selectOption.
Varshitha KVarshitha K
@Manoj kumar Jena:Link is not working
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Varshitha,

Please try below code. This code is not compiled and can be used to understand selection manipulation.
 
<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectList value="{!countries}" multiselect="true">
            <apex:selectOptions value="{!items1}"/>
        </apex:selectList><p/>
		
		 <apex:selectList value="{!countries2}" multiselect="true">
            <apex:selectOptions value="{!items2}"/>
        </apex:selectList><p/>

        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>

    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel>
                    <p>You have selected:</p>
                    <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
</apex:page>
            
/*** Controller: ***/
    public class sampleCon {
        String[] countries1 = new String[]{};
		String[] countries2 = new String[]{};
            
        public PageReference test() {
			//Here based upon your logic
			Now you have 2 selectoption list. you can manipulate it however you want it.
			Items1.addAll(Items2);
            return null;
        }
            
        public List<SelectOption> getItems1() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            return options;
        }
		
		public List<SelectOption> getItems2() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            return options;
        }
            
        public String[] getCountries() {
            return countries;
        }
            
        public void setCountries(String[] countries) {
            this.countries = countries;
        }
    }

Let us know if it helps you.