dotnetmonitor.com

 
Index
Previous
Next

 

Control validation occurs when a Control loses focus (see Controlling the Binding Operation for more information). When the user Tabs off the TextBox, validation occurs and the data binding engine (Binding type) will attempt and update the data source property with the bound Control value (TextBox.Text). If an exception occurs, validation will fail and the focus will not leave the bound Control. To allow focus to leave, you can add a BindingComplete event handler and set e.Cancel to false:

/*******************************************************************

* Setup (using the Visual Studio Form designer):

*

* Add 1 TextBox to the Form (textBox1)

*

* Add the following public property to the Form class:

*

* private int _intValue;

*

* public int IntegerValue

* {

* get { return _intValue; }

* set { _intValue = value; }

* }

*

* Add the following code to the Form.Load event:

******************************************************************/

 

Binding tbBinding = new Binding("Text", this, "IntegerValue", true);

 

/* Add binding */

this.textBox1.DataBindings.Add(tbBinding);

 

/* Hook BindingComplete to allow navigation */

tbBinding.BindingComplete += delegate(object bind, BindingCompleteEventArgs args)

{

/* Allow user to Tab off */

args.Cancel = false;

};

}

Simple Binding
Complex Binding
Using Simple Binding with a List
Sample: Simple Binding to a List (VS 2005) (VS Project: DataBinding Intro)
Type Conversion
Formatting