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

I have List_A = { Title, Type} & List_B = { Title, myLookUpField }

I want myLookUpField = Title, IF(Type=="Red")

I know....

List_B.Fields.AddLookUp("myLookUpField", List_A.ID, false);
SPFieldLookUp myCol = new SPFieldLookUp(List_B.Fields,"myLookUpField");
myCol.LookUpField = List_A.Fields["Title"].InternalName;

Im not sure how to properly restrict it to only accepting ListItems from List_A where Type is set to "Red"

Filtered Field? calulated Field? addDependent lookup? associated field?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

I would venture the following solution (there may be an easier solution, if so I'd love to know it also):

Create a custom field type with Visual Studio that extends SPFieldLookup (this video helped me to get started down that path: http://www.youtube.com/watch?v=VPhYXgKRKq8 ).

Your custom field type can filter the lookup dropdown by a "related field" value in the field control class. You can also add validation if you wish to ensure the selected value does indeed meet the filter criteria... Here is a link to more info on the SPFieldLookup class: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx

It seems daunting at first but once you understand how custom fields can be created by extending SharePoint field types (like SPFieldLookup) it is actually quite straightforward.

share|improve this answer
    
That is a really good video thanks for that. I solved it by using an SPFieldChoice in List B, then creating List A with an event receiver that adds and deletes choice fields to List B accordingly. –  user13186 Dec 6 '12 at 23:25
    
Good work my friend. It appears that you have found there are often 10 ways to skin a cat when it comes to SharePoint custom development ;) –  mikey Dec 7 '12 at 21:30
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.