SPFieldLookup.IsDependentLookup property
Gets a Boolean value that indicates whether the field is a secondary lookup field that depends on a primary field for its relationship with the lookup list.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Property value
Type: System.Booleantrue if the lookup field is a dependent lookup field; otherwise, false.
When this property returns true, the current SPFieldLookup object represents a secondary column in a multiple column lookup. In this case, the object's PrimaryFieldId property has a value that is the string representation of a GUID that identifies the object that represents the primary column on which the secondary column depends for its relationship to the lookup list.
The following example is a console application that examines the collection of fields associated with a list, looking for SPFieldLookup objects. When it finds one, code in the application determines whether the object represents a primary or secondary column. If the object represents a secondary column, the code uses the value returned by the PrimaryFieldId property to get the display name of the primary column.
using System; using Microsoft.SharePoint; namespace ConsoleApp { class Program { static void Main(string[] args) { using (SPSite siteCollection = new SPSite("http://localhost")) { using (SPWeb site = siteCollection.OpenWeb()) { SPList list = site.Lists["Complete Orders"]; foreach (SPField item in list.Fields) { if (item is SPFieldLookup) { SPFieldLookup field = (SPFieldLookup)item; if (!String.IsNullOrEmpty(field.LookupList) && !String.IsNullOrEmpty(field.LookupField)) { // Is this the primary or secondary field for a list relationship? string strRelationship = field.IsRelationship ? "Primary":"Secondary"; // Print the display name of the field. Console.WriteLine("\nField: {0} ({1} Field)", field.Title, strRelationship); // Is this a secondary field in a list relationship? if (field.IsDependentLookup) { SPField primaryField = list.Fields[new Guid(field.PrimaryFieldId)]; Console.WriteLine("Primary Field: {0}", primaryField.Title); } } } } } } Console.Write("\nPress ENTER to continue..."); Console.ReadLine(); } } }