Sams Teach Yourself .Net in 21 Days
- Table of Contents
- Copyright
- About the Author
- About the Technical Editor
- Acknowledgments
- We Want to Hear from You
- Introduction
- Week 1: At a Glance
- Day 1. Introduction to the Microsoft .NET Framework
- Day 2. Introduction to Visual Studio .NET
- Day 3. Writing Windows Forms Applications
- Day 4. Deploying Windows Forms Applications
- Day 5. Writing ASP.NET Applications
- Day 6. Deploying ASP.NET Applications
- Day 7. Exceptions, Debugging, and Tracing
- Week 1. In Review
- Week 2: At a Glance
- Day 8. Core Language Concepts in Visual Basic .NET and C#
- Day 9. Using Namespaces in .NET
- Day 10. Accessing Data with ADO.NET
- Day 11. Understanding Visual Database Tools
- Day 12. Accessing XML in .NET
- Day 13. XML Web Services in .NET
- Day 14. Components and .NET
- Week 2. In Review
- Week 3: At a Glance
- Day 15. Writing International Applications
- Day 16. Using Macros in Visual Studio .NET
- Day 17. Automating Visual Studio .NET
- Day 18. Using Crystal Reports
- Day 19. Understanding Microsoft Application Center Test
- Day 20. Using Visual SourceSafe
- Day 21. Object Role Modeling with Visio
- Week 3. In Review
Understanding Databinding
In Visual Basic 6, the RecordSet object gives you the ability to bind data from a database to text boxes, data grids, and labels. The RecordSet keeps track of the positioning through its event model. You simply call methods such as MoveFirst, MoveNext, MovePrevious, and MoveLast to navigate records in the RecordSet, and the RecordSet magically handles it for you.
In .NET, the DataSet binds its data to controls. Because the DataSet is simply a container of data, it has no knowledge of positioning. To implement code like MoveFirst and MoveNext, you must set up a BindingContext for the controls that are being databound. .NET uses the inherited CurrencyManager class to internally handle the navigation within the BindingContext of the DataSet and the controls that it's binding to.
To understand this better, consider the following Visual Basic .NET code for the btnNavNext that the Data Form Wizard created:
Private Sub btnNavNext_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnNavNext.Click
Me.BindingContext(objdsCustomers, "Customers").Position = _
(Me.BindingContext(objdsCustomers, "Customers").Position + 1)
Me.objdsCustomers_PositionChanged()
End Sub
To navigate, the current position must be maintained within the DataSet. You can keep track of this yourself, but it's easier to let the Position property of the BindingContext class handle the positioning for you. When controls are databound on a Windows Form, they're part of the BindingContext of the form, so using the Position property is an easy way to handle navigation.
Summary | Next Section

Account Sign In
View your cart