DataView.Find 方法

定義

依據指定的排序索引鍵值,找出 DataView 中的資料列。Finds a row in the DataView by the specified sort key value.

多載

Find(Object[])

依據指定的排序索引鍵值,找出 DataView 中的資料列。Finds a row in the DataView by the specified sort key values.

Find(Object)

依據指定的排序索引鍵值,找出 DataView 中的資料列。Finds a row in the DataView by the specified sort key value.

Find(Object[])

依據指定的排序索引鍵值,找出 DataView 中的資料列。Finds a row in the DataView by the specified sort key values.

public:
 int Find(cli::array <System::Object ^> ^ key);
public int Find (object[] key);
member this.Find : obj[] -> int
Public Function Find (key As Object()) As Integer

參數

key
Object[]

值的陣列,類型為 ObjectAn array of values, typed as Object.

傳回

DataView 中第一個資料列的位置索引,其符合指定的排序索引鍵值;否則,如果沒有符合的排序索引鍵值,則為 -1。The index of the position of the first row in the DataView that matches the sort key values specified; otherwise -1 if there are no matching sort key values.

範例

下列 Visual Basic 範例使用Find方法, 在其排序索引鍵資料行中, 傳回包含指定值的資料列索引。The following Visual Basic example uses the Find method to return the index of a row that contains specified values in its sort key columns.

Private Sub FindValueInDataView(table As DataTable)
    Dim view As New DataView(table)
    view.Sort = "Customers"

    ' Find the customer named "John Smith".
    Dim vals(1) As Object
    vals(0)= "John"
    vals(1) = "Smith"
    Dim i As Integer = view.Find(vals)
    Console.WriteLine(view(i))
End Sub

另請參閱

Find(Object)

依據指定的排序索引鍵值,找出 DataView 中的資料列。Finds a row in the DataView by the specified sort key value.

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

參數

key
Object

要搜尋的物件。The object to search for.

傳回

DataView 中的資料列索引,其包含指定的排序索引鍵值;如果排序索引鍵值不存在,則為 -1。The index of the row in the DataView that contains the sort key value specified; otherwise -1 if the sort key value does not exist.

範例

下列 Visual Basic 範例會使用Find方法來傳回資料列的索引, 該資料列包含您想要之排序關鍵字資料行中的值。The following Visual Basic example uses the Find method to return the index of the row that contains the value in the sort key column that you want.

Private Sub FindValueInDataView(table As DataTable)
    Dim view As New DataView(table)
    view.Sort = "CustomerID"

    ' Find the customer named "DUMON" in the primary key column
    Dim i As Integer = view.Find("DUMON")
    Console.WriteLine(view(i))
End Sub

另請參閱

適用於