SPFieldCalculated 类
表示列表中的计算的字段。
继承层次结构
System.Object
Microsoft.SharePoint.SPField
Microsoft.SharePoint.SPFieldCalculated
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Class SPFieldCalculated _
Inherits SPField
用法
Dim instance As SPFieldCalculated
public class SPFieldCalculated : SPField
备注
如果设置SPFieldCalculated类的属性时,必须调用Update方法以更改将在数据库中生效。
使用Formula属性来实现对计算字段中公式。有关的公式,您可以使用不同种类的信息,请参阅Calculated Field Formulas。
备注
Windows SharePoint Services 3.0不支持继承此类。
示例
下面的示例创建计算的字段的列表中,并将其添加到视图。计算的字段显示"是"如果 MyColumn2 的值大于 MyColumn1。
Dim webSite As SPWeb = SPContext.Current.Site.AllWebs("MyWebSite")
Try
Dim list As SPList = webSite.Lists("MyList")
Dim fields As SPFieldCollection = list.Fields
Dim newFieldName As String = fields.Add("MyNewColumn", SPFieldType.Calculated, False)
Dim newField As SPFieldCalculated = CType(fields(newFieldName), SPFieldCalculated)
newField.Formula = "=[MyColumn1]<[MyColumn2]"
newField.Update()
Dim view As SPView = list.Views("MyView")
Dim viewFields As SPViewFieldCollection = view.ViewFields
viewFields.Add(newFieldName)
view.Update()
Finally
webSite.Dispose()
End Try
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Website_Name"])
{
SPList oList = oWebsite.Lists["MyList"];
SPFieldCollection collFields = oList.Fields;
string strNewFieldName = collFields.Add("MyNewColumn",
SPFieldType.Calculated, false);
SPFieldCalculated strNewField =
(SPFieldCalculated)collFields[strNewFieldName];
strNewField.Formula = "=[Column1]<[Column2]";
strNewField.Update();
SPView oView = oList.Views["MyView"];
SPViewFieldCollection collViewFields = oView.ViewFields;
collViewFields.Add(strNewFieldName);
oView.Update();
}
备注
某些对象实现IDisposable接口,并必须避免后不再需要保留这些对象在内存中。好的编码做法有关的信息,请参阅Disposing Objects。
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。