1 Previous Next 

CurrencyManager a simple sample


Binding labels (or whatever) to a datagrid (actualy the datasource) is very simple. See this sample, that only needs a datagridview and three labels on a form and than pasting the code bellow in. For the version 2002/2003 the only change is a datagrid for the datagridview Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
    Dim dt As New DataTable
    dt.Columns.Add("Name")
    dt.Columns.Add("State")
    dt.LoadDataRow(New Object() {"Ken", "Florida"}, True)
    dt.LoadDataRow(New Object() {"Cor", "Holland"}, True)
    DataGridView1.DataSource = dt
    Label1.DataBindings.Add("Text", dt, "Name")
    Label2.DataBindings.Add("Text", dt, "State")
    Label2.Text = "1"
    Dim cma As CurrencyManager = DirectCast(BindingContext(dt), CurrencyManager)
    AddHandler cma.CurrentChanged, AddressOf CurrentChanged
End Sub
Private Sub CurrentChanged(ByVal sender As Object, ByVal e As EventArgs)
    Label3.Text = DirectCast(sender, CurrencyManager).Position.ToString
End Sub
End Class



1 Previous Next