Mittwoch, 12. Oktober 2011

Lookup field is empty in datasheet view when created using object model

I created a lookup field in a List using the SharePoint object model. Everything worked fine except one strange behavior:
When I display the List in the Datasheet-View the Lookuplists were empty.
I found out that opening the field in the List-Settings and saving it again solve the problem.
So I compared the field object before and after saving it using the SharePoint Manager 2010.
The difference was the value of LookupField.
 
After adding this to my code:

spList.Fields[$fieldName].LookupField = "Title"

it worked fine.