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
DeepikareddyDeepikareddy 

how to pass the values form one selectlist to other Selectilst

public class notes2 {

 public string SelectedValue{get;set;}
 
 public list<selectoption> Alloptions{get;set;}
 
 public list<selectoption> Selectedoptions{get;set;}
 
  
   public notes2(){
   getnames(); 
    }
 
  public void getnames(){
  Alloptions= new list<selectoption>();
  
  selectoption s1 = new selectoption('Ban' ,'Banglore');
  selectoption s2 = new selectoption('Hyd' ,'Hyderbad');
  selectoption s3 = new selectoption('Che' ,'Chennai');
  selectoption s4 = new selectoption('Ap' ,'Andhrapradesh');
  Alloptions.add(s1);
  Alloptions.add(s2);
  Alloptions.add(s3);
  Alloptions.add(s4);
  }
  
   public void addtolist(){
   
    system.debug('the selected values are::'+ selectedvalue);
    
   }
}

Visualforcepage:
 
<apex:page controller="notes2" >
  <apex:form id="fm">
  
  
   
   <apex:outputPanel id="test1" >
    <apex:selectList value="{!SelectedValue}"  id="slctedval" multiselect="true" size="5">
      <apex:selectOptions value="{!Alloptions}"/>
     </apex:selectList>
     
     
      
     &nbsp; &nbsp;
     <apex:commandButton value="Addtolist" />
       &nbsp; &nbsp;
       <apex:selectList id="Hydlist" multiselect="true" size="5" style="width:100px;" >
      <apex:selectOptions value="{!Selectedoptions}"/>
       </apex:selectList>
       
       <br/><br/>
      
     
       
        
         
       
  </apex:outputPanel>
   
   </apex:form>
</apex:page>

 
how to add the selected values of onepicklist to other picklist of multislect, please provide usefull links
note: Duplicates cannot be added further.
User-added image

thank you.. !
Deepika chowdary
 
Foram Rana RForam Rana R
Hi Deepika,

Use Below Code.
Change Option Values According to your requirment.

VFP
<apex:page controller="SampleController">
    <apex:form>
        <apex:panelGrid columns="3" id="abcd">
            <apex:selectList id="sel1" value="{!leftSelected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!DeselectedValues}" />
            </apex:selectList>
             
            <apex:panelGroup>
                <br/>
                <apex:image styleClass="picklistArrowRight" value="/s.gif">
                    <apex:actionSupport event="onclick" action="{!getSelect}" reRender="abcd"/>
                </apex:image>
                <br/><br/>
                <apex:image styleClass="picklistArrowLeft" value="/s.gif">
                    <apex:actionSupport event="onclick" action="{!getDeselect}" reRender="abcd"/>
                </apex:image>
            </apex:panelGroup>
            <apex:selectList id="sel2" value="{!rightSelected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!SelectedValues}" />
            </apex:selectList>
        </apex:panelGrid>
    </apex:form>
</apex:page>

Class:
public class SampleController {
     
    Set<String> picklistValues = new Set<String> {'New York','California','Texas','Los Angeles','Chicago','San Francisco', 'Washington'};
    Public List<String> leftSelected {get;set;}
    Public List<String> rightSelected {get;set;}
    Set<String> leftValues = new Set<String>();
    Set<String> rightValues = new Set<String>();
     
    public SampleController(){
        leftSelected = new List<String>();
        rightSelected = new List<String>();
        leftValues.addAll(picklistValues);
    }
     
    public PageReference getSelect(){
        rightSelected.clear();
        for(String s : leftSelected){
            leftValues.remove(s);
            rightValues.add(s);
        }
        return null;
    }
     
    public PageReference getDeselect(){    
        leftSelected.clear();
        for(String s : rightSelected){
            rightValues.remove(s);
            leftValues.add(s);
        }
        return null;
    }
     
    public List<SelectOption> getDeselectedValues(){
        List<SelectOption> options = new List<SelectOption>();
        List<String> objList = new List<String>();
        objList.addAll(leftValues);
        objList.sort();
        for(String s : objList){
            options.add(new SelectOption(s,s));
        }
        return options;
    }
     
    public List<SelectOption> getSelectedValues(){
         
        List<SelectOption> options = new List<SelectOption>();
        List<String> objList = new List<String>();
        objList.addAll(rightvalues);
        objList.sort();
        for(String s : objList){
            options.add(new SelectOption(s,s));
        }
        return options;
    }
}

Hope this helps you.
Mark as best Answer If you resolve the Issue.

Thanks,
Foram Rana
 
DeepikareddyDeepikareddy

hi Foram Rana, i am thanks for ur reply, but i have tried in a other way, jst  got stucked in the Remove functionality of selectoption 


 visualforc page:

<apex:page controller="notes2" >
  <apex:form id="fm">
  
   <apex:outputPanel id="test1" >
    <apex:selectList value="{!SelectedValue}"  id="slctedval" multiselect="true" size="5">
      <apex:selectOptions value="{!Alloptions}"/>
     </apex:selectList>
     
     
     <br/>
      
     &nbsp; &nbsp;
     <apex:commandButton value="Removielist"  action="{!Removelist}"/>
       &nbsp; &nbsp;
      
       
       <br/><br/>
      
     
       
        
         
       
  </apex:outputPanel>
   
   </apex:form>
</apex:page>

Apex class:

 
public class notes2 {

 public list<string> SelectedValue{get;set;}
 
 public list<selectoption> Alloptions{get;set;}
 
 public list<selectoption> Selectedoptions{get;set;}
 
  
   public notes2(){
   getnames(); 
    }
 
  public void getnames(){
  Alloptions= new list<selectoption>();
  selectoption s1 = new selectoption('Ban' ,'Banglore');
  selectoption s2 = new selectoption('Hyd' ,'Hyderbad');
  selectoption s3 = new selectoption('Che' ,'Chennai');
  selectoption s4 = new selectoption('Ap' ,'Andhrapradesh');
  Alloptions.add(s1);
  Alloptions.add(s2);
  Alloptions.add(s3);
  Alloptions.add(s4);
  }
  
   public void Removelist(){
   
    system.debug('the selected values are::'+ selectedvalue);
    
    for(integer i=0;i<selectedvalue.Size();i++){
    
    system.debug(selectedvalue[i]);
   
   /*
       if(RightSelectedValues[i].getValue() == RightSelectedValues){
              //Selectedfileds.remove(i);
             }
    
   */
   
    
    }
   
   
     
   }
}


iam geting an error of Getvalue is not available, in the remove functionality, can u please help me out.... !

Thanks 
Deepika
Foram Rana RForam Rana R
Hi Deepika,

Please use the below code:
public class notes2 {

 public list<string> SelectedValue{get;set;}
 
 public list<selectoption> Alloptions{get;set;}
 
 public list<selectoption> Selectedoptions{get;set;}
 
  
   public notes2(){
   getnames(); 
    }
 
  public void getnames(){
  Alloptions= new list<selectoption>();
  selectoption s1 = new selectoption('Ban' ,'Banglore');
  selectoption s2 = new selectoption('Hyd' ,'Hyderbad');
  selectoption s3 = new selectoption('Che' ,'Chennai');
  selectoption s4 = new selectoption('Ap' ,'Andhrapradesh');
  Alloptions.add(s1);
  Alloptions.add(s2);
  Alloptions.add(s3);
  Alloptions.add(s4);
  }
  
   public void Removelist(){
   
    system.debug('the selected values are::'+ selectedvalue);
    
    for(integer i=0;i<selectedvalue.Size();i++){
    
    system.debug(selectedvalue[i]);
   //Alloptions.remove(selectedvalue[i]);
        
        if(Alloptions[i].getValue() == selectedvalue[i]){
            Alloptions.remove(i);
        }
    
    }
   
   
     
   }
}

Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana.