+ Start a Discussion

How to display the multi picklist field as checkboxes in visualforce page?

I have created a multi-select picklist in a object.I want to display this as checkboxes in the visualforce page.How to extract the multi-picklist field values to the visual force page in the form of check boxes?
Please provide me the solution
I believe you'll need to use describeFieldResult to read the values of the multi-select list, and then add them to a SelectOption List and then pass that to a selectCheckboxes component in your page.

More info on describeFieldResult can be found in the Apex Reference Guide and info on SelectOption can be found in the Visualforce Guide.

List<SelectOption> softwareVendors = new List<SelectOption>();
Schema.DescribeFieldResult vendorField = Schema.sObjectType.Opportunity.fields.Software_Vendor__c;
Schema.PicklistEntry [] values = vendorField.getPickListValues();
for(Schema.PicklistEntry val : values){
 softwareVendors.add(new SelectOption(val.getValue(), val.getLabel()));

Message Edited by TehNrd on 07-17-2008 09:42 AM
public List<Selectoption> getCommpref()
        List<SelectOption> Commprefvalue = new List<SelectOption>();
        Schema.DescribeFieldResult CommprefField = Schema.sObjectType.Account.fields.Communication_Preferences__c; 
        Schema.PicklistEntry [] Commpref = CommprefField.getPickListValues();
        //Schema.PicklistEntry [] values = vendorField.getPickListValues();
        for(Schema.PicklistEntry val : Commpref)
            Commprefvalue.add(new SelectOption(val.getValue(), val.getLabel()));
        return Commprefvalue;        

This is the code i used in the controller part.It is retrieving the multi picklist values.But the problem is, the values are not getting aligned properly. Is there any possibility to retrieve the values individually?

And it is not navigating to the next page.Moreover the values whatever i select should be updated to the database.That is also not happening.

Here i am calling the method Commpref
<apex:selectCheckboxes value="{!Fields}">
                    <apex:selectoptions value="{!Commpref}"></apex:selectoptions>

Please provide me the solution.


Arvind010 wrote:
the values are not getting aligned properly. Is there any possibility to retrieve the values individually? 

What does not aligned properly mean?

For the values to be updated you need to apply the fields list to the Communication_Preferences__c and then execute an update DML on the obect.
How to apply the fields list to the Communication_Preferences__c?I dont know how to add the fields.Can you please provide me the sample code?

Regarding alignment...The values of the multi picklist are Business Critical Storage,Data Recovery and Protection,Desktop Storage,External Storage,Home Media (Video) Storage,Mission Critical Storage,etc
Alignment should be like this:
Business Critical Storage                        Data Recovery and Protection
Desktop Storage                                      External Storage
Home Media (Video) Storage                   Mission Critical Storage
Notebook Storage                                    Ruggedized Storage
Is there any option for layout for this alignment?

Message Edited by Arvind010 on 07-21-2008 04:30 AM

Message Edited by Arvind010 on 07-21-2008 04:31 AM

Message Edited by Arvind010 on 07-21-2008 04:31 AM
List<SelectOption> Commprefvalue = new List<SelectOption>(); needs to be a global variable. 

Then: Communication_Preferences__c = Commprefvalue;

Not sure about the layout issue.
In my code, Account instance is profileinfo.I gave profileinfo.Communication_Preferences__c = Commprefvalue.It is showing the following error if i use like this.

Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Account
I tried in someother ways also.But i am getting errors.Please provide me the solution.

Message Edited by Arvind010 on 07-22-2008 06:57 AM
rajesh k 10rajesh k 10
           How to display dynamically comming multipicklist values as Checkboxes?