共用方式為


SPFieldLookup.IsDependentLookup property

取得布林值,這個值,指出欄位是否為第二個 [查詢] 欄位的查閱清單與它關聯的主要欄位而定。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public ReadOnly Property IsDependentLookup As Boolean
    Get
'用途
Dim instance As SPFieldLookup
Dim value As Boolean

value = instance.IsDependentLookup
public bool IsDependentLookup { get; }

Property value

Type: System.Boolean
true如果 [查詢] 欄位是相依的查閱欄位 ;否則, false。

備註

當這個屬性會傳回true時,目前的SPFieldLookup物件代表多個資料行對應中的第二個資料行。在此情況下,物件的PrimaryFieldId屬性有識別物件,表示次要的資料行所依賴的查閱清單及其關聯性的主資料行的 GUID 的字串表示的值。

Examples

下列範例是主控台應用程式,會檢查欄位] 清單中,尋找SPFieldLookup物件相關聯的集合。當它會尋找第一時,應用程式中的程式碼會判斷物件是否表示主要或次要的資料行。如果該物件代表第二個資料行,程式碼會使用PrimaryFieldId屬性所傳回的值來取得主資料行的顯示名稱。

using System;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite siteCollection = new SPSite("https://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();
        }
    }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using siteCollection As New SPSite("https://localhost")
            Using site As SPWeb = siteCollection.OpenWeb()
                Dim list As SPList = site.Lists("Pending Orders")

                For Each item As SPField In list.Fields
                    If TypeOf item Is SPFieldLookup Then
                        Dim field As SPFieldLookup = DirectCast(item, SPFieldLookup)

                        If Not String.IsNullOrEmpty(field.LookupList) AndAlso Not String.IsNullOrEmpty(field.LookupField) Then
                            ' Is this the primary or secondary field for a list relationship?
                            Dim strRelationship As String = If(field.IsRelationship, "Primary", "Secondary")

                            ' Print the display name of the field.
                            Console.WriteLine(vbLf & "Field: {0} ({1} Field)", field.Title, strRelationship)

                            ' Is this a secondary field in a list relationship?
                            If field.IsDependentLookup Then
                                Dim primaryField As SPField = list.Fields(New Guid(field.PrimaryFieldId))
                                Console.WriteLine("Primary Field: {0}", primaryField.Title)
                            End If
                        End If
                    End If
                Next
            End Using
        End Using
        Console.Write(vbLf & "Press ENTER to continue...")
        Console.ReadLine()
    End Sub
End Module

請參閱

參照

SPFieldLookup class

SPFieldLookup members

Microsoft.SharePoint namespace

PrimaryFieldId

IsRelationship

AddDependentLookup(String, Guid)