Using the BindingNavigator Control

The BindingNavigator control is added to your form when you use drag-and-drop binding, but you're free to use it on your own to build a custom data binding mechanism. This control inserts yet another layer between your user and the BindingSource. In my example, I used the BindingSource control dragged from the Toolbox to wire to a strongly typed Data Source. Can it be used with a conventional DataTable (or, better yet, its DataView)? Sure.

By default, the BindingNavigator control is hard-docked at the top of your form, but you can set its docking location to other locations on the form. Its default configuration (as shown in Figure 7.19) includes most of the same buttons I used in my custom ToolStrip control (shown previously in Figure 7.17), along with a couple others. It's a handy way to get a running start on your own custom ToolStrip control.

Figure 7.19. The default layout of the BindingNavigator control.

Note that while the default BindingNavigator button configuration includes "+" (AddNew) and "X" (Delete) buttons, it does not include a "Save" (Update) button for some reason. However, if you click the "tasks" button, you can generate an entire series of "standard" buttons, including the save, print, help, and other function buttons shown in Figure 7.20. On the other hand, this bevy of beautiful buttons may be too bountiful a blessingforcing you to implement more code than you had planned for. If you use drag-and-drop data binding, the Visual Studio UI adds the Update (diskette) icon to the BindingNavigator ToolStrip for you.

Figure 7.20. The addition of "Standard Items" to the BindingNavigator ToolStrip.

The BindingNavigator control's property page exposes a number of canned methods to help set up calls to appropriate code to execute the move methods discussed earlier in this chapter, as well as to the data action query invocations to add a new row and change or delete existing rows. I suggest you use drag-and-drop binding to see how Visual Studio configures the control and connects it to the BindingSource properties and methods.

Once you have a bindable data source, setting up the BindingSource and BindingNavigator controls is a bit tedious but not that hard. What's missing are a few nuances that the code generated by drag-and-drop takes care of for you automatically. For example, once you set all of the method pointers in the BindingNavigator properties window (as shown in Figure 7.21), you'll still need to set the BindingNavigator CountItem and PositionItem properties. That code, along with the other hookup code, is included in the BindingNavigatorExample on the DVD.

Figure 7.21. Set the BindingNavigator Move method pointers.

Hitchhiker's Guide to Visual Studio and SQL Server(c) Best Practice Architectures and Examples
Hitchhikers Guide to Visual Studio and SQL Server: Best Practice Architectures and Examples, 7th Edition (Microsoft Windows Server System Series)
ISBN: 0321243625
EAN: 2147483647
Year: 2006
Pages: 227

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: