Compartir a través de


ListObject.DataBindingFailure Event

Definition

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

public:
 event EventHandler ^ DataBindingFailure;
event EventHandler DataBindingFailure;
member this.DataBindingFailure : EventHandler 
Event DataBindingFailure As EventHandler 

Event Type

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.

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);
}
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

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);
}
WithEvents List4 As ListObject

Private Sub ListObject_DataBindingFailure()
    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Me.Application.Worksheets(1)
    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
            Globals.Factory.GetVstoObject(NativeWorksheet)
    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

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.

Applies to