The dataview's find method will return the row number of the first match
of a sorted column.
Therefore is used a dataview and a currencymanager
Here a sample which we have done this time using the Data designer because we had not much of those on our website.
To test the sample you only need the Northwind DataBase (Access or SQL Server) and to drag a DataGridView on the form
The code is VB10SP1 style so for earlier versions you have to add always the byval and in some versions the continutation characters if needed
Untitled 1
Public Class Form1
'VB10 SP1 style code
'Done with the designer and the customerTable of Nortwind
'Data -> Select Add New DataSource -> DataBase -> DataSet
'and follow the wizard until the end
Private Sub Form1_Load(sender As System.Object,
e As System.EventArgs) Handles MyBase.Load
Dim dt As New NorthwindDataSet.CustomersDataTable
Using da As New NorthwindDataSetTableAdapters.CustomersTableAdapter
da.Fill(dt)
End Using
DataGridView1.DataSource = dt.DefaultView
'The casting below is only done to show,
' how to do it if it is not in the load method
Dim cm = CType(Me.BindingContext(DataGridView1.DataSource),
CurrencyManager)
Dim dv = CType(DataGridView1.DataSource, DataView)
dv.Sort = "CustomerID"
Dim x = dv.Find("ANTON")
DataGridView1.Rows(x).Selected = True
End Sub
End Class