ListObject.DataBindingFailure Event (2007 System)

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

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

Syntax

'Declaration
Public Event DataBindingFailure As EventHandler
'Usage
Dim instance As ListObject 
Dim handler As EventHandler 

AddHandler instance.DataBindingFailure, handler
public event EventHandler DataBindingFailure
public:
 event EventHandler^ DataBindingFailure {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
JScript does not support events.

Remarks

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.

Examples

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.

WithEvents List4 As Microsoft.Office.Tools.Excel.ListObject

Private Sub ListObject_DataBindingFailure()
    List4 = Me.Controls.AddListObject( _
        Me.Range("A1", "C4"), "List4")
End Sub 


Private Sub List4_DataBindingFailure(ByVal sender As Object, _
    ByVal e As EventArgs) Handles List4.DataBindingFailure
    MessageBox.Show("Data binding is " & _
    List4.IsBinding)
End Sub
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.

WithEvents List4 As ListObject

Private Sub ListObject_DataBindingFailure()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    List4 = vstoWorksheet.Controls.AddListObject( _
        vstoWorksheet.Range("A1", "C4"), "List4")
End Sub 


Private Sub List4_DataBindingFailure(ByVal sender As Object, _
    ByVal e As EventArgs) Handles List4.DataBindingFailure
    System.Windows.Forms.MessageBox.Show("Data binding is " & _
    List4.IsBinding)
End Sub
ListObject list4;
private void ListObject_DataBindingFailure()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    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);
}

.NET Framework Security

See Also

Reference

ListObject Class

ListObject Members

Microsoft.Office.Tools.Excel Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.