BindingSource.Find 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
데이터 원본에서 지정된 항목을 찾습니다.
오버로드
| Name | Description |
|---|---|
| Find(PropertyDescriptor, Object) |
지정된 속성 설명자가 있는 항목의 인덱스 검색 |
| Find(String, Object) |
지정된 속성 이름 및 값을 사용하여 목록에 있는 항목의 인덱스 값을 반환합니다. |
Find(PropertyDescriptor, Object)
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
지정된 속성 설명자가 있는 항목의 인덱스 검색
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 .
반품
지정된 값이 있는 항목의 인덱스(0부터 시작하는 인덱스)입니다 PropertyDescriptor.
구현
예외
기본 목록은 형식 IBindingList이 아닙니다.
예제
다음 코드 예제에서는 메서드를 사용 하는 방법을 보여 줍니다 Find . 전체 예제는 클래스 개요 항목을 참조하세요.
void button1_Click(object sender, EventArgs e)
{
if (!binding1.SupportsSearching)
{
_ = 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 메서드에 대한 요청을 참조합니다. 예를 들어 기본 데이터 원본이 < a0/>
추가 정보
적용 대상
Find(String, Object)
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
- Source:
- BindingSource.cs
지정된 속성 이름 및 값을 사용하여 목록에 있는 항목의 인덱스 값을 반환합니다.
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 메서드에 대한 요청을 참조합니다. 예를 들어 기본 데이터 원본이 또는 DataSetDataTable이 메서드가 DataViewa propertyName 로 변환 PropertyDescriptor 되고 메서드를 호출하는 IBindingList.Find 경우 일치하는 항목이 없는 경우 반환되는 값과 같은 동작 Find은 기본 목록의 메서드 구현에 따라 달라집니다.
속성 이름 비교는 대/소문자를 구분하지 않습니다.