Condividi tramite


SPViewFieldCollection Class

Represents the collection of fields returned in a view.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPViewFieldCollection

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<SubsetCallableTypeAttribute> _
<ClientCallableTypeAttribute(Name := "ViewFieldCollection", CollectionChildItemType := GetType(String),  _
    ServerTypeId := "{AF975F76-8A94-4e6d-8325-BD1E20B7C301}")> _
Public Class SPViewFieldCollection _
    Inherits SPBaseCollection
'Usage
Dim instance As SPViewFieldCollection
[SubsetCallableTypeAttribute]
[ClientCallableTypeAttribute(Name = "ViewFieldCollection", CollectionChildItemType = typeof(string), 
    ServerTypeId = "{AF975F76-8A94-4e6d-8325-BD1E20B7C301}")]
public class SPViewFieldCollection : SPBaseCollection

Remarks

Use the ViewFields property of the SPQuery, SPView, or SPViewStyle class to return an SPViewFieldCollection object that represents the collection of view fields for a query, view, or view style. Use an indexer to return a single view field from the collection. For example, if the collection is assigned to a variable named collViewFields, use myViewFields[index] in C#, or myViewFields(index) in Visual Basic, where index is the index number of the field in the collection.

Examples

The following code example removes the Modified field from the specified view of an Announcements list and adds the Expires field to the view.

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("Announcements")
Dim view As SPView = list.Views(1)

view.ViewFields.Delete("Modified")

view.ViewFields.Add("Expires")

view.Update() 
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPList oList = oWebsite.Lists["Announcements"];
    SPView oView = oList.Views[1];
    oView.ViewFields.Delete("Modified");
    oView.ViewFields.Add("Expires");
    oView.Update();
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

SPViewFieldCollection Members

Microsoft.SharePoint Namespace