Search
VB
-
Tips
Visual Basic .Net tips and tricks
1
Previous
Next
CurrencyManager a simple sample
Synchronise labels (or whatever) with a DataGridView (actually the datasource) is very simple.
Take a look at this sample. It needs only a Form Project with dragged on that a DataGridView and three labels.
You can paste the code below into the code view and click the green start button in top (or F5)
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
Syndication
Rss feed
Select a Category
General Grid Tips
DataGrid Tips
DataGridView Tips
Windows Forms Controls
General Ado.Net Tips
SqlClient Ado.Net Tips
OleDB Ado.Net Tips
Asp.Net Tips
Miscellanous Tips
Vista programming Tips
WPF Tips
Silverlight
Articles
Links
Code Camp
FAQs
VB Related Websites
Microsoft Visual Basic Home Page
Visual Basic .Net Wikipedia Page
Visual Basic Forums
Visual Basic Newsgroup
VB City
Thinq Linq
VB Helper
I love VB