This documentation is archived and is not being maintained.

ConstraintCollection.RemoveAt Method

Removes the Constraint object at the specified index from the collection.

[Visual Basic]
Public Sub RemoveAt( _
   ByVal index As Integer _
)
[C#]
public void RemoveAt(
 int index
);
[C++]
public: void RemoveAt(
 int index
);
[JScript]
public function RemoveAt(
   index : int
);

Parameters

index
The index of the Constraint to remove.

Exceptions

Exception Type Condition
IndexOutOfRangeException The collection does not have a constraint at this index.

Remarks

The IndexOf method returns the index of a given Constraint.

Before using the RemoveAt method, you can use the Contains method to determine if the collection contains the target Constraint, and the CanRemove method to determine if a Constraint can be removed.

The CollectionChanged event occurs if the constraint is successfully removed.

Example

[Visual Basic, C#, C++] The following example uses the IndexOf method in conjunction with the RemoveAt method to remove a constraint from the ConstraintCollection.

[Visual Basic] 
Private Sub RemoveConstraint _
(myConstraints As ConstraintCollection, myConstraint As Constraint)
    Try
        If myConstraints.Contains(myConstraint.ConstraintName) Then
            If myConstraints.CanRemove(myConstraint) Then
                myConstraints.RemoveAt _
                (myConstraints.IndexOf(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.RemoveAt(myConstraints.IndexOf(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->RemoveAt(myConstraints->IndexOf(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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

ConstraintCollection Class | ConstraintCollection Members | System.Data Namespace | CanRemove | Contains | IndexOf

Show: