次の方法で共有


SPViewFieldCollection.Add method (String)

Adds the field with the specified name to the collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Sub Add ( _
    strField As String _
)
'Usage
Dim instance As SPViewFieldCollection
Dim strField As String

instance.Add(strField)
public void Add(
    string strField
)

Parameters

  • strField
    Type: System.String

    A string that contains the field name.

Remarks

The Add 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 uses the Add method to make an existing field a view field for the 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.Add("Field_Name")

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;
    collViewFields.Add("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.

See also

Reference

SPViewFieldCollection class

SPViewFieldCollection members

Add overload

Microsoft.SharePoint namespace