Okay with Clay's assistance I came up with the following which works but not
sure if there is slimming down that could be done. If you have any
suggestions please post them. Otherwise the credit goes to Clay on this.
Imports System.Data.OleDb
Public Class Form1
Dim BindingSource1 As Windows.Forms.BindingSource = New BindingSource
Dim TheCurrencyManager As CurrencyManager
Dim pkValue As Object
Property FieldValue() As Object
Get
Return pkValue
End Get
Set(ByVal value As Object)
pkValue = value
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=example.mdb;"
Dim TheConnection As OleDbConnection = New
OleDbConnection(strConnection)
Dim da As New OleDbDataAdapter("SELECT * FROM Customers ORDER BY id",
TheConnection)
Dim dv As DataView
Dim ds As New DataSet
da.Fill(ds, "customers")
dv = New DataView(ds.Tables("customers"))
TheCurrencyManager = CType(Me.BindingContext(dv), CurrencyManager)
DataGridView1.DataSource = dv
BindingSource1.DataSource = dv
End Sub
Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
With DataGridView1
FieldValue = .Item(0, .CurrentRow.Index).Value ' Get ID field value
End With
End Sub
Private Sub DataGridView1_Sorted(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGridView1.Sorted
TheCurrencyManager.Position = BindingSource1.Find("ID",
DirectCast(FieldValue, Integer))
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdClose.Click
Close()
End Sub
End Class