RemoteBindableComponent.DataBindings 屬性 (2007 系統)

更新:2007 年 11 月

取得元件的 Binding 物件。

命名空間:  Microsoft.VisualStudio.Tools.Office
組件:  Microsoft.Office.Tools.v9.0 (在 Microsoft.Office.Tools.v9.0.dll 中)

語法

Public ReadOnly Property DataBindings As ControlBindingsCollection

Dim instance As RemoteBindableComponent
Dim value As ControlBindingsCollection

value = instance.DataBindings
public ControlBindingsCollection DataBindings { get; }

屬性值

型別:System.Windows.Forms.ControlBindingsCollection

ControlBindingsCollection,包含元件的 Binding 物件。

實作

IBindableComponent.DataBindings

備註

使用這個屬性存取 ControlBindingsCollection。將 Binding 物件加入至集合,您便可以將元件的任何屬性繫結至物件的屬性。

範例

下列程式碼範例會將單一儲存格的 NamedRange 控制項 (衍生自 RemoteBindableComponent)、具有單一名稱欄的 DataSet,以及 Button 加入至目前的工作表中。範例會使用 DataBindings 屬性,將 DataSet 繫結至 NamedRangeValue2 屬性。這個程式碼範例是 RemoteBindableComponent 類別完整範例的一部分。

Private namedRange1 As Microsoft.Office.Tools.Excel.NamedRange
Private WithEvents button1 As Microsoft.Office.Tools.Excel.Controls.Button
Private customerNames As String() = _
    {"Reggie", "Sally", "Henry", "Christine"}
Private ds As DataSet

Private Sub SetBindingContext()
    namedRange1 = Me.Controls.AddNamedRange(Me.Range("A1", _
        System.Type.Missing), "namedRange1")

    ' Create a button that scrolls through the data 
    ' displayed in the NamedRange.
    button1 = Me.Controls.AddButton(50, 20, 100, 20, "button1")
    button1.Text = "Display next item"

    ' Create a data table with one column.
    ds = New DataSet()
    Dim table As DataTable = ds.Tables.Add("Customers")
    Dim column1 As New DataColumn("Names", GetType(String))
    table.Columns.Add(column1)

    ' Add the names to the table.
    Dim row As DataRow
    Dim i As Integer
    For i = 0 To customerNames.Length - 1
        row = table.NewRow()
        row("Names") = customerNames(i)
        table.Rows.Add(row)
    Next i

    ' Create a new Binding that links the Value2 property
    ' of the NamedRange and the Names column.
    Dim binding1 As New Binding("Value2", ds, "Customers.Names", True)
    namedRange1.DataBindings.Add(binding1)
End Sub
private Microsoft.Office.Tools.Excel.NamedRange namedRange1;
private Microsoft.Office.Tools.Excel.Controls.Button button1;
private string[] customerNames = 
    { "Reggie", "Sally", "Henry", "Christine" };
private DataSet ds;

private void SetBindingContext()
{
    namedRange1 = this.Controls.AddNamedRange(
        this.Range["A1", missing], "namedRange1");

    // Create a button that scrolls through the data 
    // displayed in the NamedRange.
    button1 = this.Controls.AddButton(50, 20, 100, 20,
        "button1");
    button1.Text = "Display next item";
    button1.Click += new EventHandler(button1_Click);

    // Create a data table with one column.
    ds = new DataSet();
    DataTable table = ds.Tables.Add("Customers");
    DataColumn column1 = new DataColumn("Names", typeof(string));
    table.Columns.Add(column1);

    // Add the names to the table.
    DataRow row;
    for (int i = 0; i < customerNames.Length; i++)
    {
        row = table.NewRow();
        row["Names"] = customerNames[i];
        table.Rows.Add(row);
    }

    // Create a new Binding that links the Value2 property
    // of the NamedRange and the Names column.
    Binding binding1 = new Binding("Value2", ds, "Customers.Names", true);
    namedRange1.DataBindings.Add(binding1);
}

使用權限

請參閱

參考

RemoteBindableComponent 類別

RemoteBindableComponent 成員

Microsoft.VisualStudio.Tools.Office 命名空間