The Binding Class

Team-Fly team-fly    

 
ADO.NET Programming in Visual Basic .NET
By Steve  Holzner, Bob  Howell

Table of Contents
Chapter 8.   Data Binding in Windows Forms


The Binding class and the BindingCollection facilitate data binding on the control's side. We saw some of this in the previous example of binding to an array. We can actually see the contents of the Binding collection if we click the Advanced tab of a control with a DataBindings property. This looks like Figure 8.11 for the TextBox control.

Figure 8.11. The Data Binding collection editor.

graphics/08fig11.gif

As you can see, you can bind almost any property to a bindable object. This could come in very handy if you wanted to be able to create forms at runtime using data stored in database tables or XML files.

The Bindable attribute we've mentioned is actually only used to make a property appear in the DataBindings area of the Properties window and allow it to be bound at design time. Any property can be bound at runtime.

Well, almost any property: In order to be able to be bound, a property must be a basic data type and return only a single value. You can't bind to complex objects or an array of values, for example. The reasons for this should be obvious.

The Binding class supports the following properties and events:

  • Control Returns the control the binding is attached to.

  • DataSource Gets the DataSource object for the binding.

  • IsBinding Returns a value indicating if the binding is active. The Suspend and Resume binding methods of the BindingContext control this.

  • PropertyName The name of the property of the control the binding applies to.

  • Format Event Fires when the control needs to update its display of the data.

  • Parse Event Fires when the control is going to update the data source with a new value.

The BindingCollection supports the following methods:

  • Add Adds a new binding object to the collection.

  • Clear Clears all of the bindings for this control.

  • Remove; RemoveAt Removes a binding from the collection.

  • CollectionChanged Event Fires when the collection changes, through an Add or Remove method.


Team-Fly team-fly    
Top


ADO. NET Programming in Visual Basic. NET
ADO.NET Programming in Visual Basic .NET (2nd Edition)
ISBN: 0131018817
EAN: 2147483647
Year: 2005
Pages: 123

Similar book on Amazon

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