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
Hussey786Hussey786 

multiselect picklist with checkboxes in visualorce

Hi All,

Please help me to develope a VF page with multiselet drop down with checkboxes in visualforce.

User-added image

Thanks in advance,

Regards,
Hussey
Vijay NagarathinamVijay Nagarathinam
Hi,

Go through the following link, I think it will be helpful for you.

https://hisrinu.wordpress.com/2011/05/30/custom-multi-select-picklist-field-in-visualforce/

https://developer.salesforce.com/blogs/developer-relations/2012/06/a-multiselect-picklist-visualforce-component.html
Hussey786Hussey786
Thank you Vijay, but i need the picklist as shown in image uplaoded. I don't want to use add and remove buttons.
Vijay NagarathinamVijay Nagarathinam
Hi,

Try this code it will work 
 
<apex:page controller="sampleCon">
    <apex:form >
        <apex:selectCheckboxes value="{!countries}">
            <apex:selectOptions value="{!items}"/>
        </apex:selectCheckboxes><br/>
        <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>
 
public class sampleCon {
    String[] countries = new String[]{};

    public PageReference test() {
        return null;
    }

    public List<SelectOption> getItems() {
        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;
    }
}

I think it will be helpful for you.