dotnetmonitor.com

 
Index
Previous
Next

 

In VS 2005, a new event named BindingComplete was added to the Binding type to provide general information on the completion state of a binding operation. When using simple binding, you can use this event to call EndEdit to automatically commit changes on an instance that supports IEditableObject (e.g. ADO.NET DataRowView).

/* Bind the CheckBox.Checked property to the data source property Prop */

/* Update the data source when the Checked property value changes */

cb.DataBindings.Add("Checked", ds, "Prop", true, DataSourceUpdateMode.OnPropertyChanged);

 

/* Get the binding could have manually created and added the binding as well */

Binding adoBinding = cb.DataBindings["Checked"];

 

/* Force EndEdit for ADO.NET */

adoBinding.BindingComplete += delegate(object binding, BindingCompleteEventArgs args)

{

if ((args.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate) &&

(args.BindingCompleteState == BindingCompleteState.Success))

{

DataRowView drv = (args.Binding.BindingManagerBase.Current as DataRowView);

 

/* Force ADO.NET to commit the value */

if (null != drv)

{

drv.EndEdit();

}

}

};

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