.NET Framework Class Library
IBindingList..::.Find Method

Returns the index of the row that has the given PropertyDescriptor.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
Function Find ( _
    property As PropertyDescriptor, _
    key As Object _
) As Integer
Visual Basic (Usage)
Dim instance As IBindingList
Dim property As PropertyDescriptor
Dim key As Object
Dim returnValue As Integer

returnValue = instance.Find(property, _
    key)
C#
int Find(
    PropertyDescriptor property,
    Object key
)
Visual C++
int Find(
    PropertyDescriptor^ property, 
    Object^ key
)
JScript
function Find(
    property : PropertyDescriptor, 
    key : Object
) : int

Parameters

property
Type: System.ComponentModel..::.PropertyDescriptor
The PropertyDescriptor to search on.
key
Type: System..::.Object
The value of the property parameter to search for.

Return Value

Type: System..::.Int32
The index of the row that has the given PropertyDescriptor.
Exceptions

ExceptionCondition
NotSupportedException

SupportsSearching is false.

Remarks

This method will select the first row where the value of the property parameter equals the value of the key parameter.

This method is supported if SupportsSearching is true, otherwise this method throws a NotSupportedException.

Examples

The following code example demonstrates how to implement the Find method.

Visual Basic
Public Class MyFontList
    Inherits BindingList(Of Font)

    Protected Overrides ReadOnly Property SupportsSearchingCore() As Boolean
        Get
            Return True
        End Get
    End Property

    Protected Overrides Function FindCore(ByVal prop As PropertyDescriptor, _
        ByVal key As Object) As Integer
        ' Ignore the prop value and search by family name.
        Dim i As Integer
        While i < Count
            If Items(i).FontFamily.Name.ToLower() = CStr(key).ToLower() Then
                Return i
            End If
            i += 1
        End While

        Return -1
    End Function
End Class
C#
    public class MyFontList : BindingList<Font>
    {

        protected override bool SupportsSearchingCore
        {
            get { return true; }
        }
        protected override int FindCore(PropertyDescriptor prop, object key)
        {
            // Ignore the prop value and search by family name.
            for (int i = 0; i < Count; ++i)
            {
                if (Items[i].FontFamily.Name.ToLower() == ((string)key).ToLower())
                    return i;

            }
            return -1;
        }


    }

}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
See Also

Reference

Tags :


Page view tracker