Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

Example

[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)
    Try
        If myConstraints.Contains(myConstraint.ConstraintName) Then
            If myConstraints.CanRemove(myConstraint) Then
                myConstraints.Remove(myConstraint.ConstraintName)
            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"
         log.WriteEntry(e.ToString())
         Console.WriteLine("Exception of type {0} occurred.", e.GetType().ToString())
    End Try
End Sub

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

[C++] 
private:
 void RemoveConstraint(ConstraintCollection* myConstraints, Constraint* myConstraint){
    try{
       if(myConstraints->Contains(myConstraint->ConstraintName)) {
          if(myConstraints->CanRemove(myConstraint)) {
             myConstraints->Remove(myConstraint->ConstraintName);
          }
       }
    }
    catch(Exception* e) {
    // Process exception and return.
        System::Diagnostics::EventLog* log = new System::Diagnostics::EventLog();
        log->Source = S"My Application";
        log->WriteEntry(e->ToString());
        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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.