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
Soumya sri yaravaSoumya sri yarava 

hi all, how can i uncheck the other value , selected two samevalues time in wrapper class

hi all, if i select any two two common names, need not to allow user check other same name, or unselect the other if selected other
Ex: If andhrapradesh is selected , again selected as andhrapradesh, need to unselect  the other andhrapradesh. 
please let me know the how can i proceed..
 or a boolean set to false..! 
Visual force page:
<apex:page controller="test3">
   <apex:form >
   <apex:pageBlock >
      <apex:pageblockTable value="{!wraplist}"  var="a">
       <apex:column ><apex:inputCheckbox value="{!a.selected}"/>{!a.name}</apex:column>
       </apex:pageblockTable>
    <apex:commandButton value="OrderSelected"  reRender="one,two" action="{!duplicatecheck}"/>
       <apex:outputLabel id="two">{!listSelectedNames}</apex:outputLabel>
    </apex:pageBlock>
   </apex:form>
</apex:page>

ApexClass:
 
public class test3{
 public list<string>listSelectedNames{get;set;}
 public list<Wrapperclass>wraplist{get;set;}
 public list<Wrapperclass> containslistcheck{get;set;}

  
  public test3(){
 listSelectedNames = new list<string>();
containslistcheck  = new list<Wrapperclass>(); 
 
 wraplist = new list<Wrapperclass>();
   Wrapperclass   wf = new Wrapperclass();
                  wf.selected=false;
                  wf.name ='AndhraPradesh';
                 
    Wrapperclass   wf1 = new Wrapperclass();
                  wf1.selected=false;
                  wf1.name ='Telangana';
                                  
   Wrapperclass   wf2 = new Wrapperclass();
                  wf2.selected=false;
                  wf2.name ='Chennai';
                
     Wrapperclass   wf3= new Wrapperclass();
                  wf3.selected=false;
                  wf3.name ='AndhraPradesh';
                  
                  
     Wrapperclass   wf4= new Wrapperclass();
                  wf4.selected=false;
                  wf4.name ='Karnataka';
                  
                  
     Wrapperclass   wf5 = new Wrapperclass();
                  wf5.selected=false;
                  wf5.name ='Telangana';            
                
          wraplist.add(wf);
          wraplist.add(wf1);
          wraplist.add(wf2);
          wraplist.add(wf3);
          wraplist.add(wf4);
         wraplist.add(wf5);
 }
 
 
   public void duplicatecheck(){
    listSelectedNames.clear();
   
    
    for(wrapperclass wrap: wraplist){
        if(wrap.selected == true){
           
            listSelectedNames.add(wrap.Name);
           
         }  
    }
    
    system.debug(listSelectedNames);
}


 //wrapper classs
    public class Wrapperclass{
       public boolean selected{get;set;}
       public string Name{get;set;}
    }
  
  
}

User-added image

any suggestions are welcomed.

Thanks 
Soumya sree
 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Sowmya,

You could add them to a set before showing and then display only the items in the set.

As set has unique values you should be able to use it.

I hope this helps and in case if this comes handy could you please choose this as best answer so that it can be used by others in the future,

Regards,
Anutej
Soumya sri yaravaSoumya sri yarava
hi, while displaying i need to display all the duplicates also, but while selecting i cannot select the duplicates, can i know how i can  do it

thanks 
soumya