SPViewFieldCollection.Delete Method (String)
Deletes the field with the specified name from the collection.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "fieldDoesNotExist", Condition := "The field does not exist in the collection of view fields.", _
ErrorType := GetType(SPException), ErrorCode := )> _
<ClientCallableMethodAttribute(Name := "Remove", ClientMethodEndCodeSnippet := "OnRemove({0});")> _
Public Sub Delete ( _
strField As String _
)
'Usage
Dim instance As SPViewFieldCollection
Dim strField As String
instance.Delete(strField)
[ClientCallableExceptionConstraintAttribute(FixedId = "fieldDoesNotExist", Condition = "The field does not exist in the collection of view fields.",
ErrorType = typeof(SPException), ErrorCode = )]
[ClientCallableMethodAttribute(Name = "Remove", ClientMethodEndCodeSnippet = "OnRemove({0});")]
public void Delete(
string strField
)
Parameters
strField
Type: System.StringA string that contains the field name.
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 in a view of 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
viewFields.Delete("Field_Name")
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;
collViewFields.Delete("Field_Name");
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.