SPFieldLookup.IsDependentLookup 属性
获取一个布尔值,指示该字段是否是一个辅助的查阅字段,取决于它的关系与查阅列表的主字段。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public ReadOnly Property IsDependentLookup As Boolean
Get
用法
Dim instance As SPFieldLookup
Dim value As Boolean
value = instance.IsDependentLookup
public bool IsDependentLookup { get; }
属性值
类型:System.Boolean
true如果查阅字段是依赖型查阅字段 ;否则为false。
备注
当此属性返回true时,当前的SPFieldLookup对象所表示的多个列查找中的第二列。在这种情况下,对象的PrimaryFieldId属性具有的值的字符串表示形式表示的次栏所依赖的其关系到查阅列表的主列的对象标识的 GUID。
示例
下面的示例是一个控制台应用程序,检查列表,寻找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