ListObject.DataBindingFailure Event

 

Occurs when a condition causes the data binding of a ListObject control to fail.

Namespace:   Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

event EventHandler DataBindingFailure

An example of a condition that causes failure is if a user drops a ListObject control onto another ListObject control that is already in the drop location. The new control's data binding fails and the control raises this event.

The following code example creates a ListObject and adds an event handler for the DataBindingFailure event. If list1 is bound to a data source and then the binding fails, the event is caught and a message appears showing the state of the binding.

This version is for a document-level customization.

Microsoft.Office.Tools.Excel.ListObject list4;
private void ListObject_DataBindingFailure()
{
    list4 = this.Controls.AddListObject(
        this.Range["A1", "C4"], "list4");
    list4.DataBindingFailure += new EventHandler(list4_DataBindingFailure);
}

void list4_DataBindingFailure(object sender, EventArgs e)
{
    MessageBox.Show("Data binding is " + list4.IsBinding);
}

This version is for an application-level add-in.

ListObject list4;
private void ListObject_DataBindingFailure()
{
    Worksheet vstoWorksheet =
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    list4 = vstoWorksheet.Controls.AddListObject(
        vstoWorksheet.Range["A1", "C4"], "list4");
    list4.DataBindingFailure += new EventHandler(list4_DataBindingFailure);
}

void list4_DataBindingFailure(object sender, EventArgs e)
{
    System.Windows.Forms.MessageBox.Show("Data binding is " + list4.IsBinding);
}
Return to top
Show: