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

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
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 '12 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 '12 at 16:58
add comment

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.