Using the BindingNavigator


Using the BindingNavigator

The 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 Basics

The 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 Actions

The 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 Item

The 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 Item

The DeleteItem property on the BindingNavigator indicates the ToolStripItem that will cause an item to be deleted.

Move First

The MoveFirstItem property on the BindingNavigator indicates the ToolStripItem that will set the position of the underlying BindingSource to the beginning of the list.

Move Last

The 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 Previous

The MovePreviousItem property of the BindingNavigator indicates the ToolStripItem that, when clicked, will move the current item pointer up one index in the list.

Move Next

The MoveNextItem property of the BindingNavigator indicates the ToolStripItem that, when clicked, will move the current item pointer down one index in the list.

Save Data

There 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.

Table 37.4. Chain of Events Starting with User Action

User Action

BindingNavigator Property

ToolStripItem Event

BindingSource Event(s)

Click New

AddNewItem

Click

AddingNew

ListChanged

CurrentChanged

CurrentItemChanged

PositionChanged

BindingComplete

Click "<<"

MoveFirstItem

Click

BindingComplete

CurrentChanged

CurrentItemChanged

PositionChanged

Click "<"

MovePreviousItem

Click

BindingComplete

CurrentChanged

CurrentItemChanged

PositionChanged

Click ">"

MoveNextItem

Click

BindingComplete

CurrentChanged

CurrentItemChanged

PositionChanged

Click ">>"

MoveLastItem

Click

BindingComplete

CurrentChanged

CurrentItemChanged

PositionChanged

Click "X"

DeleteItem

Click

CurrentChanged

CurrentItemChanged

ListChanged

Click Save

None

Click

CurrentChanged

CurrentItemChanged

ListChanged

BindingComplete




Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net