ListObject.DataBindingFailure 事件 (2007 system)

更新: 2008 年 7 月

当某个条件导致 ListObject 控件的数据绑定失败时发生。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)

语法

声明
Public Event DataBindingFailure As EventHandler
用法
Dim instance As ListObject
Dim handler As EventHandler

AddHandler instance.DataBindingFailure, handler
public event EventHandler DataBindingFailure

备注

例如,如果用户将某个 ListObject 控件放在已在该位置的另一个 ListObject 控件上,则将导致失败。新控件的数据绑定失败,该控件将引发此事件。

示例

下面的代码示例创建一个 ListObject 并为 DataBindingFailure 事件添加事件处理程序。如果 list1 绑定到数据源,而后绑定失败,则将捕获该事件,并将显示一条消息,指出绑定的状态。

此版本针对的是文档级自定义项。

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

此版本针对的是应用程序级外接程序。

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

权限

另请参见

参考

ListObject 类

ListObject 成员

Microsoft.Office.Tools.Excel 命名空间

修订记录

日期

修订记录

原因

2008 年 7 月

添加了一个针对应用程序级外接程序的代码示例版本。

SP1 功能更改。