1

When looking at an SPField object, how can I tell if it supports multiple values?

I.e. a Choice field that is displayed using Checkboxes, a Managed Metadata field that allows multiple values, Person or Group that allows multiple selections, and quite possibly something I'm not thinking of?

The best I've come up with is compiling a list of multi valued types (e.g. TaxonomyFieldTypeMulti, LookupMulti, UserMulti..) and comparing against FieldTypeAsString. I'm wondering if there's a better approach.

1 Answer 1

2

Lookup fields (which user extends) supports AllowMultipleValues.

Then you can do:

var multi = field is SPFieldMultiChoice || 
    (field is SPFieldLookup && (field as SPFieldLookup).AllowMultipleValues);

Same for Taxonomy

2
  • I think this will work for me. I don't necessarily care about supporting arbitrary custom field types, but this would also work if they inherit from something sensible. To support multi choice columns as well: field is SPFieldMultiChoice || (field is SPFieldLookup && (field as SPFieldLookup).AllowMultipleValues)
    – lgaud
    Sep 17, 2012 at 16:52
  • I updated the answer :) And yes you would have to implement all kind of checks if you want to 'cover it all' as far as I know :(
    – eirikb
    Sep 17, 2012 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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