BindingCompleteEventArgs Class

Provides data for the BindingComplete event.

System.Object
  System.EventArgs
    System.ComponentModel.CancelEventArgs
      System.Windows.Forms.BindingCompleteEventArgs

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public class BindingCompleteEventArgs : CancelEventArgs

The BindingCompleteEventArgs type exposes the following members.

  NameDescription
Public methodBindingCompleteEventArgs(Binding, BindingCompleteState, BindingCompleteContext)Initializes a new instance of the BindingCompleteEventArgs class with the specified binding, error state, and binding context.
Public methodBindingCompleteEventArgs(Binding, BindingCompleteState, BindingCompleteContext, String)Initializes a new instance of the BindingCompleteEventArgs class with the specified binding, error state and text, and binding context.
Public methodBindingCompleteEventArgs(Binding, BindingCompleteState, BindingCompleteContext, String, Exception)Initializes a new instance of the BindingCompleteEventArgs class with the specified binding, error state and text, binding context, and exception.
Public methodBindingCompleteEventArgs(Binding, BindingCompleteState, BindingCompleteContext, String, Exception, Boolean)Initializes a new instance of the BindingCompleteEventArgs class with the specified binding, error state and text, binding context, exception, and whether the binding should be cancelled.
Top

  NameDescription
Public propertyBindingGets the binding associated with this occurrence of a BindingComplete event.
Public propertyBindingCompleteContextGets the direction of the binding operation.
Public propertyBindingCompleteStateGets the completion state of the binding operation.
Public propertyCancelGets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.)
Public propertyErrorTextGets the text description of the error that occurred during the binding operation.
Public propertyExceptionGets the exception that occurred during the binding operation.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The BindingCompleteEventArgs contains information regarding exceptions or errors that occurred during a binding process.

The following code example demonstrates handling the BindingComplete event. To run this code, paste it into an empty code file.

using System;
using System.Drawing;
using System.Windows.Forms;

class Form1 : Form
{
	private BindingSource BindingSource1 = new BindingSource();
	private TextBox textBox1 = new TextBox();
	private TextBox textBox2 = new TextBox();
	private TextBox textBox3 = new TextBox();

	public Form1()
	{
		//Set up the textbox controls. 
		this.textBox1.Location = new System.Drawing.Point(82, 13);
		this.textBox1.TabIndex = 1;
		this.textBox2.Location = new System.Drawing.Point(81, 47);
		this.textBox2.TabIndex = 2;
		this.textBox3.Location = new System.Drawing.Point(81, 83);
		this.textBox3.TabIndex = 3;

		// Add the textbox controls to the form 
		this.Controls.Add(this.textBox2);
		this.Controls.Add(this.textBox1);
		this.Controls.Add(this.textBox3);

		// Handle the form's Load event. 
		this.Load += new System.EventHandler(this.Form1_Load);
	}
	Binding partNameBinding;
	Binding partNumberBinding;

	private void Form1_Load(object sender, EventArgs e)
	{
		// Set the DataSource of BindingSource1 to the Part type.
		BindingSource1.DataSource = typeof(Part);

		// Bind the textboxes to the properties of the Part type,  
		// enabling formatting.
		partNameBinding = textBox1.DataBindings.Add("Text",
			BindingSource1, "PartName", true);
		
		partNumberBinding = textBox2.DataBindings.Add("Text", BindingSource1, "PartNumber",
			true);

		//Bind the textbox to the PartPrice value with currency formatting.
		textBox3.DataBindings.Add("Text", BindingSource1, "PartPrice", true,
			DataSourceUpdateMode.OnPropertyChanged, 0, "C");
			

		// Handle the BindingComplete event for BindingSource1 and  
		// the partNameBinding.
		partNumberBinding.BindingComplete +=
			new BindingCompleteEventHandler(partNumberBinding_BindingComplete);
		partNameBinding.BindingComplete +=
			new BindingCompleteEventHandler(partNameBinding_BindingComplete);

		// Add a new part to BindingSource1.
		BindingSource1.Add(new Part("Widget", 1234, 12.45));
	}

	// Handle the BindingComplete event to catch errors and exceptions  
	// in binding process. 
	void partNumberBinding_BindingComplete(object sender,
		BindingCompleteEventArgs e)
	{
		if (e.BindingCompleteState != BindingCompleteState.Success)
			MessageBox.Show("partNumberBinding: " + e.ErrorText);
	}		

	// Handle the BindingComplete event to catch errors and  
	// exceptions in binding process. 
	void partNameBinding_BindingComplete(object sender,
		BindingCompleteEventArgs e)
	{
		if (e.BindingCompleteState != BindingCompleteState.Success)
			MessageBox.Show("partNameBinding: " + e.ErrorText);
	}

	[STAThread]
	static void Main()
	{
		Application.EnableVisualStyles();
		Application.Run(new Form1());
	}
}

// Represents a business object that throws exceptions when invalid values are 
// entered for some of its properties. 
public class Part
{
	private string name;
	private int number;
	private double price;

	public Part(string name, int number, double price)
	{
		PartName = name;
		PartNumber = number;
		PartPrice = price;
	}

	public string PartName
	{
		get { return name; }
		set
		{
			if (value.Length <= 0)
				throw new Exception("Each part must have a name.");
			else
				name = value;
		}
	}
	public double PartPrice
	{
		get { return price; }
		set { price = value; }
	}

	public int PartNumber
	{
		get { return number; }
		set
		{
			if (value < 100)
				throw new Exception("Invalid part number." +
					" Part numbers must be greater than 100.");
			else
				number = value;
		}
	}
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft