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[]

类型为 Object 的值的数组。An 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

另请参阅

适用于