ConstraintCollection.Remove 方法

定义

Constraint 中移除 ConstraintCollectionRemoves a Constraint from the ConstraintCollection.

重载

Remove(Constraint)

从集合中移除指定的 ConstraintRemoves the specified Constraint from the collection.

Remove(String)

从集合中移除按名称指定的 Constraint 对象。Removes the Constraint object specified by name from the collection.

Remove(Constraint)

从集合中移除指定的 ConstraintRemoves the specified Constraint from the collection.

public:
 void Remove(System::Data::Constraint ^ constraint);
public void Remove (System.Data.Constraint constraint);
member this.Remove : System.Data.Constraint -> unit
Public Sub Remove (constraint As Constraint)

参数

constraint
Constraint

要移除的 ConstraintThe Constraint to remove.

例外

constraint 参数为 nullThe constraint argument is null.

约束不属于该集合。The constraint does not belong to the collection.

示例

private void RemoveConstraint(DataTable table,
    Constraint constraint)
{
    if(table.Constraints.Contains(constraint.ConstraintName))
        if(table.Constraints.CanRemove(constraint))
            table.Constraints.Remove(constraint);
}
Private Sub RemoveConstraint(table As DataTable, _
    constraint As Constraint)

    If table.Constraints.Contains(constraint.ConstraintName) Then
        If table.Constraints.CanRemove(constraint) Then
            table.Constraints.Remove(constraint)
        End If
    End If
End Sub

注解

使用方法之前 Remove ,可以使用 Contains 方法来确定集合是否包含目标 Constraint ,并使用 CanRemove 方法来确定是否 Constraint 可以移除。Before using the Remove method, you can use the Contains method to determine whether the collection contains the target Constraint, and the CanRemove method to determine whether a Constraint can be removed.

CollectionChanged如果成功删除该约束,则会发生该事件。The CollectionChanged event occurs if the constraint is successfully removed.

另请参阅

适用于

Remove(String)

从集合中移除按名称指定的 Constraint 对象。Removes the Constraint object specified by name from the collection.

public:
 void Remove(System::String ^ name);
public void Remove (string name);
member this.Remove : string -> unit
Public Sub Remove (name As String)

参数

name
String

要删除的 Constraint 的名称。The name of the Constraint to remove.

示例

下面的示例 Constraint ConstraintCollection 使用方法从测试后的中移除 Contains ,以及是否可以使用方法将其移除 CanRemoveThe following example removes a Constraint from a ConstraintCollection after testing for its presence with the Contains method, and whether it can be removed with the CanRemove method.

private void RemoveConstraint(ConstraintCollection constraints,
    Constraint constraint)
{
    if(constraints.Contains(constraint.ConstraintName))
        if(constraints.CanRemove(constraint))
            constraints.Remove(constraint.ConstraintName);
}
Private Sub RemoveConstraint _
    (constraints As ConstraintCollection, constraint As Constraint)

    If constraints.Contains(constraint.ConstraintName) Then
        If constraints.CanRemove(constraint) Then
            constraints.Remove(constraint.ConstraintName)
        End If
    End If
End Sub

注解

使用方法之前 Remove ,可以使用 Contains 方法来确定集合是否包含目标 Constraint ,并使用 CanRemove 方法来确定是否 Constraint 可以移除。Before using the Remove method, you can use the Contains method to determine whether the collection contains the target Constraint, and the CanRemove method to determine whether a Constraint can be removed.

CollectionChanged如果成功删除该约束,则会发生该事件。The CollectionChanged event occurs if the constraint is successfully removed.

另请参阅

适用于