Tuesday, December 9, 2008

Allow multiple values in a List Lookup SPField

To create a new field which can select multiple options from a lookup list:
w.Fields.AddLookup(FieldName, LookupList.ID, false);
w.Fields[FieldName].Group = "My Columns";
SPFieldLookup f = (SPFieldLookup)w.Fields[FieldName];
f.AllowMultipleValues = true;
w.Fields[FieldName].Update(true);
Where:
SPWeb w is the web site to store the new column in
String FieldName is to be the new field's Name
SPList LookupList is the List containing the lookup listitems