ConstraintCollection.IndexOf Method (Constraint)

 

Gets the index of the specified Constraint.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

Public Function IndexOf (
	constraint As Constraint
) As Integer

Parameters

constraint
Type: System.Data.Constraint

The Constraint to search for.

Return Value

Type: System.Int32

The zero-based index of the Constraint if it is in the collection; otherwise, -1.

Use the IndexOf method to return an index to be used with either the Contains or Remove method.

The following example uses the IndexOf method to return the index of a Constraint. The index is passed to the Contains method, before it is removed, to determine whether the collection contains the constraint.

Private Sub RemoveConstraint _
    (constraints As ConstraintCollection, constraint As Constraint)
    Try
        If constraints.Contains(constraint.ConstraintName) Then
            If constraints.CanRemove(constraint) Then
                constraints.RemoveAt _
                (constraints.IndexOf(constraint))
            End If
        End If

    Catch e As Exception
	' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
            e.GetType().ToString())
    End Try
End Sub

.NET Framework
Available since 1.1
Return to top
Show: