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
Giri Kumar BGiri Kumar B 

when check box is check to add button click same page display value

when the check box is click one the record only That Record only display . But my code is when i check the check box select all the record after dispaly all record . i want only when which one check box click record that record only display 
ApexClass:
public class SetExample{
public List<string> lNames{set;get;}
public List<string> rNames{set;get;}
public boolean flag{set;get;}

public SetExample(){
lNames= new List<string>{'satya','manu','reddy','peeri'};
rNames=new List<string>();
flag=false;
}
public void AddValues(){

for(integer i=0;i<lNames.size();i++)
{
string value;
      if(flag==true)
        {
            value=lNames.get(i);
           rNames.add(value);
           
        }
        
      system.debug(rNames);  
}
}
}

Visual Force Page
<apex:page controller="SetExample">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="add" action="{!AddValues}" reRender="one"/>

</apex:pageBlockButtons>

</apex:pageBlock>

<apex:pageblock >

<apex:pageBlockSection >
<apex:pageBlockTable value="{!lNames}" var="n">
<apex:column >

<apex:inputCheckbox value="{!flag}"/>
</apex:column>
<apex:column value="{!n}" />
</apex:pageBlockTable>


<apex:pageBlockTable value="{!rNames}" var="r" id="one">
<apex:column value="{!r}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form> 
{!flag}
</apex:page>    
User-added image
Andrew EchevarriaAndrew Echevarria
Try adding the line below to the beginning of the AddValues function, otherwise when it adds a value for one checkbox, it doesn't remove it and the value stays when it is not needed later.
rNames=new List<string>();