Using the BindingNavigatorThe BindingNavigator class was mentioned a few times in the section on binding with typed DataSets but never in much detail. This section provides you with in-depth coverage of the BindingNavigator and how to get the most out of this powerful new control. BindingNavigator BasicsThe first and foremost thing to remember about the BindingNavigator is that it is really nothing more than a tricked-out ToolStrip. It is basically a ToolStrip that comes preloaded with VCR-like buttons that provide a user interface for moving through and manipulating the items within a BindingSource. This means that if your design doesn't call for a navigation toolstrip, you can stop building at the BindingSource and leave this component out. However, if you want users to be able to click buttons to move forward, back, to the end, and to the front, as well as being able to add and remove items, this control is definitely what you need. User-Triggered Binding ActionsThe following is a list of the actions that users can perform by clicking the various built-in buttons supplied with the BindingNavigator. Keep in mind that if need be, you can add your own custom buttons to the BindingNavigator because at its core it is still just a ToolStrip. Create New ItemThe AddNewItem property on the BindingNavigator indicates the ToolStripItem that will cause an item to be added. When this ToolStripItem is clicked, the AddNew method of the underlying BindingSource will be called. You can either use the Click event on the ToolTripItem, or you can use the AddingNew event on the BindingSource to inject your own code into the new item creation process. Delete ItemThe DeleteItem property on the BindingNavigator indicates the ToolStripItem that will cause an item to be deleted. Move FirstThe MoveFirstItem property on the BindingNavigator indicates the ToolStripItem that will set the position of the underlying BindingSource to the beginning of the list. Move LastThe MoveLastItem property of the BindingNavigator indicates the ToolStripItem that, when clicked, will set the position of the underlying BindingSource to the last item in the list. Move PreviousThe MovePreviousItem property of the BindingNavigator indicates the ToolStripItem that, when clicked, will move the current item pointer up one index in the list. Move NextThe MoveNextItem property of the BindingNavigator indicates the ToolStripItem that, when clicked, will move the current item pointer down one index in the list. Save DataThere is no special property of the BindingNavigator that points to the "Save" ToolStripItem. This is because the code that is invoked to save data is entirely your creationthere is nothing in the BindingSource responsible for saving the data to disk or database. To help you see what events you can trap and which properties are important in the chain of events, take a look at Table 37.4.
|