SPViewFieldCollection.Add 方法 (SPField)
向集合中添加指定的字段。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub Add ( _
field As SPField _
)
用法
Dim instance As SPViewFieldCollection
Dim field As SPField
instance.Add(field)
public void Add(
SPField field
)
参数
field
类型:Microsoft.SharePoint.SPField一个表示此字段的SPField对象。
备注
Add方法要求SPView类的Update方法调用以更改将在数据库中生效。
示例
下面的代码示例使用Add方法将指定的列表的视图字段的现有字段。
Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("View_Name")
Dim viewFields As SPViewFieldCollection = view.ViewFields
Dim newViewField As SPField = list.Fields("Field_Name")
viewFields.Add(newViewField)
view.Update()
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
SPList oList = oWebsite.Lists["List_Name"];
SPView oView = oList.Views["View_Name"];
SPViewFieldCollection collViewFields = oView.ViewFields;
SPField oViewField = oList.Fields["Field_Name"];
collViewFields.Add(oViewField);
oView.Update();
}
备注
某些对象实现IDisposable接口,并必须避免后不再需要保留这些对象在内存中。好的编码做法有关的信息,请参阅Disposing Objects。