Share via


SPViewFieldCollection.Delete Method (SPField)

Deletes the specified field from the collection.

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

Syntax

'Declaration
Public Sub Delete ( _
    field As SPField _
)
'Usage
Dim instance As SPViewFieldCollection
Dim field As SPField

instance.Delete(field)
public void Delete(
    SPField field
)

Parameters

Remarks

The Delete method requires that the Update method of the SPView class be called for changes to take effect in the database.

Examples

The following code example deletes a field from the collection of view fields for a specified list.

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 delViewField As SPField = list.Fields("Field_Name")

viewFields.Delete(delViewField)

view.Update() 
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];
    SPViewFieldCollection collViewFields = oView.ViewFields;
    SPField oViewFieldToDelete = oList.Fields["Field_Name"];
    collViewFields.Delete(oViewFieldToDelete);
    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.

See Also

Reference

SPViewFieldCollection Class

SPViewFieldCollection Members

Delete Overload

Microsoft.SharePoint Namespace