แก้ไข

แชร์ผ่าน


ConstraintCollection.Remove Method

Definition

Removes a Constraint from the ConstraintCollection.

Overloads

Remove(Constraint)

Removes the specified Constraint from the collection.

Remove(String)

Removes the Constraint object specified by name from the collection.

Remove(Constraint)

Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs

Removes 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)

Parameters

constraint
Constraint

The Constraint to remove.

Exceptions

The constraint argument is null.

The constraint does not belong to the collection.

Examples

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

Remarks

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.

The CollectionChanged event occurs if the constraint is successfully removed.

See also

Applies to

Remove(String)

Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs

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)

Parameters

name
String

The name of the Constraint to remove.

Examples

The 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

Remarks

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.

The CollectionChanged event occurs if the constraint is successfully removed.

See also

Applies to