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.
• Table of Contents
• Index
Sams Teach Yourself Visual Studio® .NET 2003 in 21 Days
By
Jason Beres
Publisher
: Sams Publishing
Pub Date
: January 14, 2003
ISBN
: 0-672-32421-0
Pages
: 696
Sams Teach Yourself Visual Studio .NET in 21 Days will help developers that are new to application development and experienced developers understand how to use the .NET Framework and Visual Studio .NET to rapidly develop any type of computer application. The Visual Studio .NET development environment is the most comprehensive developer tool ever created, putting that together with the .NET Frameworks' Class Libraries, the developer has everything he or she needs to get up-to-speed on Microsoft's latest revolution in application development. This book will guide the developer through using the VS .NET IDE, the Visual Basic .NET and C# language, and the supporting tools available from Microsoft to create Windows and Web-based applications. The market is full of books that pretty much say the same thing, which is already available in the help files, the author of this book has written and deployed over a dozen successful applications using Visual Studio .NET and the .NET Framework. All of his expertise and experience is used to give you the most comprehensive title on using Visual Studio .NET.