I was asked how to add this field programmatically within a feature receiver.

To do this, use the code below and replace "SourceList" and "LookupList" with the titles of your lists.

SPWeb web = SPContext.Current.Web; //Replace to call for (SPWeb)properties.Feature.Parent in feature receiver
SPList list = web.Lists["SourceList"];
SPList lookupList = web.Lists["LookupList"];

ExtendedLookupField newField = (ExtendedLookupField)list.Fields.CreateNewField("ExtendedLookup", "New Lookup Column");
newField.AddMissingValue = false;
newField.AllowMultipleValues = false;
newField.LookupWebId = lookupList.ParentWeb.ID;
newField.LookupList = lookupList.ID.ToString("B");
newField.LookupViewId = lookupList.DefaultView.ID;
newField.LookupField = "Title";

list.Fields.Add(newField);

Last edited Nov 25, 2009 at 9:53 AM by Lekman, version 3

Comments

DThomas Nov 26, 2009 at 4:12 PM 
Great, it works.
I missed the line where you create the new field