This documentation is archived and is not being maintained.

ConstraintCollection.Remove Method

Removes a Constraint from the ConstraintCollection.

Overload List

Removes the specified Constraint from the collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Remove(Constraint)
[C#] public void Remove(Constraint);
[C++] public: void Remove(Constraint*);
[JScript] public function Remove(Constraint);

Removes the Constraint object specified by name from the collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Remove(String)
[C#] public void Remove(string);
[C++] public: void Remove(String*);
[JScript] public function Remove(String);


[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Remove. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub RemoveConstraint _
(myConstraints As ConstraintCollection, myConstraint As Constraint)
        If myConstraints.Contains(myConstraint.ConstraintName) Then
            If myConstraints.CanRemove(myConstraint) Then
            End If
        End If
    Catch e As Exception
    ' Process exception and return.
         Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog()
         log.Source = "My Application"
         Console.WriteLine("Exception of type {0} occurred.", e.GetType().ToString())
    End Try
End Sub

private void RemoveConstraint(ConstraintCollection myConstraints, Constraint myConstraint){
      if(myConstraints.Contains(myConstraint.ConstraintName)) {
         if(myConstraints.CanRemove(myConstraint)) {
   catch(Exception e) {
   // Process exception and return.
       System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
       log.Source = "My Application";
       Console.WriteLine("Exception of type {0} occurred.", e.GetType());

 void RemoveConstraint(ConstraintCollection* myConstraints, Constraint* myConstraint){
       if(myConstraints->Contains(myConstraint->ConstraintName)) {
          if(myConstraints->CanRemove(myConstraint)) {
    catch(Exception* e) {
    // Process exception and return.
        System::Diagnostics::EventLog* log = new System::Diagnostics::EventLog();
        log->Source = S"My Application";
        Console::WriteLine(S"Exception of type {0} occurred.", e->GetType());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ConstraintCollection Class | ConstraintCollection Members | System.Data Namespace