Binding

Binding

System. Windows .Forms (system. windows .forms.dll) class

This class is used in the data-binding framework to bind a property on an object to a property on a Control (e.g., the Name property of a business object to the Text property on a Control ). This process is called simple binding.

A bag of these bindings are held by a BindingManagerBase that manages a set of related bindings. The binding manager makes sure the current value in the data source is reflected in each Binding it contains.

Finally, a bag of binding managers is called a BindingContext . The BindingContext is associated with a particular control and contains all the binding managers for all the controls owned by that container.

The Binding is created by specifying the name of the Control property to which you are binding (e.g., "Text"), the object that is going to provide the data (e.g., a hypothetical Employee business object), and a string that determines the property to be used on the data source (e.g., the Employee object Name ). This final parameter can be an empty string to bind to the value of the object itself, the name of a property on the object, or a dot-separated path navigating to the appropriate property (e.g., through the tables and relations of a System.Data.DataSet ). These are subsequently obtained through the Control , DataSource , and PropertyName properties of the Binding class.

When the Binding is created, it automatically finds a binding manager for the data source in the Control objects BindingContext and adds itself. You can find this binding manager with the Item property (the index for the class).

The Binding object also provides two events that allow you to control the data-binding process more closely.

The Format event is raised whenever data is transferred into the Control . You can use it to modify the information as it is transferred, converting from one data type to another to get over those awkward impedance problems when there is no default data type converter.

The other half of this partnership is the Parse event. It allows you to perform the conversion back the other way when the Control data is transferred back to the bound object. The Parse event is raised if the Control objects Validated event occurs, if EndCurrentEdit() is called on the BindingManagerBase , or if the Position changes on the BindingManagerBase (i.e., the Current object in the data binding changes). For the standard Control objects (such as ListBox and DataGrid ), these events occur automatically and the binding proceeds normally without your intervention.

 public class  Binding  {  // Public Constructors  public  Binding  (string  propertyName  , object  dataSource  , string  dataMember  );  // Public Instance Properties  public BindingManagerBase  BindingManagerBase  {get; }    public BindingMemberInfo  BindingMemberInfo  {get; }    public Control  Control  {get; }    public object  DataSource  {get; }    public bool  IsBinding  {get; }    public string  PropertyName  {get; }  // Protected Instance Methods  protected virtual void  OnFormat  (ConvertEventArgs  cevent  );    protected virtual void  OnParse  (ConvertEventArgs  cevent  );  // Events  public event ConvertEventHandler  Format  ;    public event ConvertEventHandler  Parse  ; } 

Returned By

BindingsCollection.this , ControlBindingsCollection.this

Passed To

BindingsCollection.{AddCore() , RemoveCore()} , ControlBindingsCollection.{Add() , Remove()}



. Net Windows Forms in a Nutshell
.NET Windows Forms in a Nutshell
ISBN: 0596003382
EAN: 2147483647
Year: 2002
Pages: 794

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