BindingSource.Find 메서드

정의

데이터 소스에서 지정된 항목을 찾습니다.

오버로드

Find(PropertyDescriptor, Object)

지정된 속성 설명자가 있는 항목의 인덱스를 검색합니다.

Find(String, Object)

목록에서 지정된 속성 이름 및 값을 가진 항목의 인덱스를 반환합니다.

Find(PropertyDescriptor, Object)

지정된 속성 설명자가 있는 항목의 인덱스를 검색합니다.

public:
 virtual int Find(System::ComponentModel::PropertyDescriptor ^ prop, System::Object ^ key);
public virtual int Find (System.ComponentModel.PropertyDescriptor prop, object key);
abstract member Find : System.ComponentModel.PropertyDescriptor * obj -> int
override this.Find : System.ComponentModel.PropertyDescriptor * obj -> int
Public Overridable Function Find (prop As PropertyDescriptor, key As Object) As Integer

매개 변수

prop
PropertyDescriptor

검색할 PropertyDescriptor입니다.

key
Object

일치시킬 prop 값입니다.

반환

지정된 PropertyDescriptor 값이 있는 항목의 0부터 시작하는 인덱스입니다.

구현

예외

기본 목록이 IBindingList 형식이 아닌 경우

예제

다음 코드 예제에서는 Find 메서드를 사용하는 방법을 보여 줍니다. 전체 예제 클래스 개요 항목을 참조 하세요.

private void button1_Click(object sender, EventArgs e)
{
    if (binding1.SupportsSearching != true)
    {
        MessageBox.Show("Cannot search the list.");
    }
    else
    {
        int foundIndex = binding1.Find("Name", textBox1.Text);
        if (foundIndex > -1)
            listBox1.SelectedIndex = foundIndex;
        else
            MessageBox.Show("Font was not found.");
    }
}
    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles button1.Click

        If binding1.SupportsSearching <> True Then
            MessageBox.Show("Cannot search the list.")
        Else
            Dim foundIndex As Integer = binding1.Find("Name", textBox1.Text)
            If foundIndex > -1 Then
                listBox1.SelectedIndex = foundIndex
            Else
                MessageBox.Show("Font was not found.")
            End If
        End If

    End Sub
End Class

설명

첫 번째 행에서 지정 된 필드의 값을 찾고 복잡 한 데이터 바인딩된 경우이 메서드는 일반적으로 사용 합니다 prop 매개 변수 값과는 key 매개 변수

이 메서드는 단순히 요청 내부 목록에 참조 IBindingList.Find 메서드. 예를 들어 기본 데이터 원본이 DataSet, DataTable, 또는 DataView,이 메서드를 호출 합니다 DataView.IBindingList.Find 메서드. 동작 IBindingList.Find와 같은 내부 목록에 있는 메서드의 구현에 따라 일치 하는 항목이 없으면 반환 되는 값입니다.

추가 정보

적용 대상

Find(String, Object)

목록에서 지정된 속성 이름 및 값을 가진 항목의 인덱스를 반환합니다.

public:
 int Find(System::String ^ propertyName, System::Object ^ key);
public int Find (string propertyName, object key);
member this.Find : string * obj -> int
Public Function Find (propertyName As String, key As Object) As Integer

매개 변수

propertyName
String

검색할 속성의 이름입니다.

key
Object

검색하려고 지정한 propertyName을 가진 항목의 값입니다.

반환

지정된 속성 이름 및 값을 가진 항목의 0부터 시작하는 인덱스입니다.

예외

기본 목록이 검색 기능이 구현된 IBindingList가 아닌 경우

propertyName이 목록의 속성과 일치하지 않는 경우

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다 합니다 Find 메서드는 DataView합니다. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 PopulateDataViewAndFind 폼의 생성자에서 또는 Load 이벤트 처리 메서드. 폼을 가져와야 합니다 System.XmlSystem.IO 네임 스페이스입니다.

private void PopulateDataViewAndFind()
{
    DataSet set1 = new DataSet();

    // Some xml data to populate the DataSet with.
    string musicXml =
        "<?xml version='1.0' encoding='UTF-8'?>" +
        "<music>" +
        "<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" +
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" +
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" +
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" +
        "</music>";

    // Read the xml.
    StringReader reader = new StringReader(musicXml);
    set1.ReadXml(reader);

    // Get a DataView of the table contained in the dataset.
    DataTableCollection tables = set1.Tables;
    DataView view1 = new DataView(tables[0]);

    // Create a DataGridView control and add it to the form.
    DataGridView datagridview1 = new DataGridView();
    datagridview1.AutoGenerateColumns = true;
    this.Controls.Add(datagridview1);

    // Create a BindingSource and set its DataSource property to
    // the DataView.
    BindingSource source1 = new BindingSource();
    source1.DataSource = view1;

    // Set the data source for the DataGridView.
    datagridview1.DataSource = source1;

    // Set the Position property to the results of the Find method.
    int itemFound = source1.Find("artist", "Natalie Merchant");
    source1.Position = itemFound;
}
Private Sub PopulateDataViewAndFind() 
    Dim set1 As New DataSet()
    
    ' Some xml data to populate the DataSet with.
    Dim musicXml As String = "<?xml version='1.0' encoding='UTF-8'?>" & _
        "<music>" & _
        "<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" & _
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" & _
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" & _
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" & _
        "</music>"
    
    ' Read the xml.
    Dim reader As New StringReader(musicXml)
    set1.ReadXml(reader)
    
    ' Get a DataView of the table contained in the dataset.
    Dim tables As DataTableCollection = set1.Tables
    Dim view1 As New DataView(tables(0))
    
    ' Create a DataGridView control and add it to the form.
    Dim datagridview1 As New DataGridView()
    datagridview1.AutoGenerateColumns = True
    Me.Controls.Add(datagridview1)
    
    ' Create a BindingSource and set its DataSource property to
    ' the DataView.
    Dim source1 As New BindingSource()
    source1.DataSource = view1
    
    ' Set the data source for the DataGridView.
    datagridview1.DataSource = source1
    
    ' Set the Position property to the results of the Find method.
    Dim itemFound As Integer = source1.Find("artist", "Natalie Merchant")
    source1.Position = itemFound

End Sub

설명

Find 메서드 내부 목록인 경우에 사용 수를 IBindingList 검색 기능이 구현 된 합니다. 이 메서드는 단순히 요청 내부 목록에 참조 IBindingList.Find 메서드. 예를 들어 기본 데이터 원본이 DataSet, DataTable, 또는 DataView,이 메서드는 변환 propertyNamePropertyDescriptor 호출를 IBindingList.Find 메서드. 동작 Find와 같은 내부 목록에 있는 메서드의 구현에 따라 일치 하는 항목이 없으면 반환 되는 값입니다.

속성 이름 비교는 대/소문자입니다.

적용 대상