This documentation is archived and is not being maintained.

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 ref class BindingCompleteEventArgs : public 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 a hash function for a particular type. (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.


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

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

        property String^ PartName 
        {
            String^ get()
            {
                return name;
            }

            void set(String^ value)
            {
                if (value->Length <= 0)
                {
                    throw gcnew Exception(
                        "Each part must have a name.");
                }
                else
                {
                    name = value;
                }
            }
        }

        property double PartPrice 
        {
            double get()
            {
                return price;
            }

            void set(double value)
            {
                price = value;
            }
        }

        property int PartNumber 
        {
            int get()
            {
                return number;
            }

            void set(int value)
            {
                if (value < 100)
                {
                    throw gcnew Exception(
                        "Invalid part number." \
                        "Part numbers must be " \
                        "greater than 100.");
                }
                else
                {
                    number = value;
                }
            }
        }

    };

    ref class MainForm: public Form
    {
    private:
        BindingSource^ bindingSource;
        TextBox^ partNameTextBox;
        TextBox^ partNumberTextBox;
        TextBox^ partPriceTextBox;

    public:
        MainForm()
        {
            bindingSource = gcnew BindingSource;
            partNameTextBox = gcnew TextBox;
            partNumberTextBox = gcnew TextBox;
            partPriceTextBox = gcnew TextBox;

            //Set up the textbox controls.
            this->partNameTextBox->Location = Point(82, 13);
            this->partNameTextBox->TabIndex = 1;
            this->partNumberTextBox->Location = Point(81, 47);
            this->partNumberTextBox->TabIndex = 2;
            this->partPriceTextBox->Location = Point(81, 83);
            this->partPriceTextBox->TabIndex = 3;

            // Add the textbox controls to the form
            this->Controls->Add(this->partNumberTextBox);
            this->Controls->Add(this->partNameTextBox);
            this->Controls->Add(this->partPriceTextBox);

            // Handle the form's Load event.
            this->Load += gcnew EventHandler(this, 
                &MainForm::OnMainFormLoad);
        }

    private:

        void OnMainFormLoad(Object^ sender, EventArgs^ e)
        {   
            // Set the DataSource of bindingSource to the Part type.
            bindingSource->DataSource = Part::typeid;

            // Bind the textboxes to the properties of the Part type,
            // enabling formatting.
            partNameTextBox->DataBindings->Add(
                "Text", bindingSource, "PartName", true);
            partNumberTextBox->DataBindings->Add(
                "Text", bindingSource, "PartNumber", true);

            //Bind the textbox to the PartPrice value 
            // with currency formatting.
            partPriceTextBox->DataBindings->Add("Text", bindingSource, "PartPrice", true,
               DataSourceUpdateMode::OnPropertyChanged, nullptr, "C");

            // Handle the BindingComplete event for bindingSource and
            // the partNameBinding.
            bindingSource->BindingComplete += 
                gcnew BindingCompleteEventHandler(this, 
                &MainForm::OnBindingSourceBindingComplete);
            bindingSource->BindingComplete += 
                gcnew BindingCompleteEventHandler(this, 
                &MainForm::OnPartNameBindingBindingComplete);

            // Add a new part to bindingSource.
            bindingSource->Add(gcnew Part("Widget", 1234, 12.45));
        }

        // Handle the BindingComplete event to catch errors and 
        // exceptions in binding process.
        void OnBindingSourceBindingComplete(Object^ sender, 
            BindingCompleteEventArgs^ e)
        {
            if (e->BindingCompleteState == 
                BindingCompleteState::Exception)
            {
                MessageBox::Show(String::Format(
                    CultureInfo::CurrentCulture,
                    "bindingSource: {0}", e->Exception->Message));
            }

            if (e->BindingCompleteState == 
                BindingCompleteState::DataError)
            {
                MessageBox::Show(String::Format(
                    CultureInfo::CurrentCulture,
                    "bindingSource: {0}", e->Exception->Message));
            }
        }

        // Handle the BindingComplete event to catch errors and 
        // exceptions in binding process.
        void OnPartNameBindingBindingComplete(Object^ sender, 
            BindingCompleteEventArgs^ e)
        {
            if (e->BindingCompleteState == 
                BindingCompleteState::Exception)
            {
                MessageBox::Show(String::Format(
                    CultureInfo::CurrentCulture,
                    "PartNameBinding: {0}", e->Exception->Message));
            }

            if (e->BindingCompleteState == 
                BindingCompleteState::DataError)
            {
                MessageBox::Show(String::Format(
                    CultureInfo::CurrentCulture,
                    "PartNameBinding: {0}", e->Exception->Message));
            }
        }
    };



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.
Show: