Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How do get choices from a Sharepoint list, so the users has a way to define new choices.

Right now I have defined fields in elements.xml, but that is static.

Anybody know how? I would be really great!

Kevin Simper

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Kevin, you can change column values manually once deployed or you can use code to change it. You can use a feature receiver to modify choices if you simply want to change values.

Here isn example for you:

    private void UpdateFields(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;
        SPWeb web = site.RootWeb;

       SPFieldMultiChoice myChoice = (SPFieldMultiChoice)web.Fields["ChoiceField"];
        myChoice .Choices.Add("Yes");
        myChoice .Choices.Add("No");
        myChoice .PushChangesToLists = true;
        myChoice .Update();

}

You can update or delete choices this way too.

share|improve this answer

Create a custom list. Supply the choice in the title column. Save. Repeat as necessary. Create a lookup column in the desired list where the choices should be, point it to the Title column.

Now users (I'd limit the editors) can add items to the first list and choices will appear (or disappear if deleted) in the second.

share|improve this answer
    
It sounds really cool, are you talking about the splookupfield for the lookup? How do you do that in the elements.xml? –  Kevin Simper Jun 25 '12 at 6:17
    
by setting <Field Type="Lookup" overwrite="TRUE" List="Lists/secondlist" xxx /> –  Steve B Jun 25 '12 at 14:27

Not sure what you mean by static, but you can definitely edit the column and add new choices. But if you want to have your choices in another list, you might want to use lookup field as opposed to choice field.

share|improve this answer
    
<Field ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB18}" Name="CostCenter" DisplayName="Department" Type="Choice" Required="FALSE" Group="Financial Columns"> <CHOICES> <CHOICE>Administration</CHOICE> <CHOICE>Information</CHOICE> <CHOICE>Facilities</CHOICE> <CHOICE>Operations</CHOICE> <CHOICE>Sales</CHOICE> <CHOICE>Marketing</CHOICE> </CHOICES> </Field> This is static, but i want to get the choices from a sharepoint list. Choice field is what i am looking for. –  Kevin Simper Jun 22 '12 at 15:00
    
I don't think you can have a choice field driven by a SharePoint list. But you can edit the site column after deployment and add new choices if you want. –  sssreddy Jun 22 '12 at 15:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.