IBindingList


The minimum level of usable data binding functionality for list data sources really comprises all that we've seen so far:

  • Support for both simple and complex binding models

  • The ability to add, update, and delete items on both bound controls and list data sources

  • The issuing of list and list item change notifications

This and other related functionality is encapsulated by the IBindingList data binding interface:

namespace System.ComponentModel {   interface IBindingList : IList, ... {     // List management     bool AllowEdit { get; set; }     bool AllowNew { get; set; }     bool AllowRemove { get; set; }     object AddNew();     // List change notification     bool SupportsChangeNotification { get; }     event ListChangedEventHandler ListChanged;     // Sorting     bool SupportsSorting { get; }     ... // Rest of sorting members elided     // Searching     bool SupportsSearching { get; }     ... // Rest of searching members elided   } }


IBindingList is a well-known data binding infrastructure contract that extends IList with data-binding-specific functionality for list data sources. IBindingList implementations must support the list management members of the interface to let users add, update, and delete list data source items (via AllowEdit, AllowNew, and AllowRemove) and to provide a hook into the item adding process with AddNew. List change notification, sorting, and searching, unlike list management, can be optionally implemented, a fact that's advertised by SupportsChangeNotification, SupportsSorting, and SupportsSearching, respectively.

If list change notification is supported, bound controls can subscribe to the ListChanged event to notice when items are added, updated, or removed and thereby keep their displayed data synchronized with the list data source. If sorting or searching is provided, bound controls like DataGridView can tailor their UIs with additional elements to provide a mechanism for users to exercise these capabilities;[4] DataGridView enables sorting via column header clicking, and it paints a special arrow glyph in the sorted column to indicate sort order.

[4] Using searching and sorting is shown in Chapter 17. While it's beyond the scope of this book to discuss how to implement sorting and searching custom data sources, it's nicely covered in Brian Noyes's book Data Binding with Windows Forms 2.0 : Programming Smart Client Data Applications with .NET (Addison-Wesley, 2006).

IBindingList is the interface you implement to add list management and list change notification to your list data sources, which might themselves implement IEnumerable, ICollection, and IList. Unfortunately, this is a nontrivial exercise. Fortunately, it's also an unnecessary exercise because BindingList<T> implements these elements of IBindingList for you.




Windows Forms 2.0 Programming
Windows Forms 2.0 Programming (Microsoft .NET Development Series)
ISBN: 0321267966
EAN: 2147483647
Year: 2006
Pages: 216

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