RemoteBindableComponent-Klasse (2007 System)

Aktualisiert: November 2007

Stellt eine Standardimplementierung der IBindableComponent-Schnittstelle für Hoststeuerelemente in Visual Studio Tools for Office-Projektmappen bereit.

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

Syntax

<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public MustInherit Class RemoteBindableComponent _
    Inherits RemoteComponent _
    Implements IBindableComponent, IComponent, IDisposable

Dim instance As RemoteBindableComponent
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public abstract class RemoteBindableComponent : RemoteComponent, 
    IBindableComponent, IComponent, IDisposable

Hinweise

Hoststeuerelemente, die an Daten gebunden werden können, erben von der RemoteBindableComponent-Klasse. Diese Klasse ist nicht für die direkte Verwendung im Code vorgesehen.

Weitere Informationen zu Hoststeuerelementen finden Sie unter Übersicht über Hostelemente und Hoststeuerelemente.

Beispiele

Im folgenden Codebeispiel werden dem aktuellen Arbeitsblatt ein NamedRange-Steuerelement (abgeleitet von RemoteBindableComponent) mit einer einzelnen Zelle, ein DataSet mit einer einzelnen Namensspalte sowie ein Button hinzugefügt. Im Beispiel wird die DataBindings-Eigenschaft verwendet, um das DataSet an die Value2-Eigenschaft von NamedRange zu binden. Wenn auf den Button geklickt wird, wird die BindingContext-Eigenschaft verwendet, um den nächsten Namen in NamedRange anzuzeigen.

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

' Displays the next data item in the NamedRange.
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
    Handles button1.Click

    If Not (namedRange1.BindingContext Is Nothing) Then
        Dim bindingManager1 As BindingManagerBase = _
            namedRange1.BindingContext(ds, "Customers")

        ' Display the next item.
        If bindingManager1.Position < bindingManager1.Count - 1 Then
            bindingManager1.Position += 1

            ' Display the first item.
        Else
            bindingManager1.Position = 0
        End If
    End If
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);
}

// Displays the next data item in the NamedRange.
void button1_Click(object sender, EventArgs e)
{
    if (namedRange1.BindingContext != null)
    {
        BindingManagerBase bindingManager1 =
            namedRange1.BindingContext[ds, "Customers"];

        // Display the next item.
        if (bindingManager1.Position < bindingManager1.Count - 1)
        {
            bindingManager1.Position++;
        }

        // Display the first item.
        else
        {
            bindingManager1.Position = 0;
        }
    }
}

Vererbungshierarchie

System.Object
  Microsoft.VisualStudio.Tools.Office.RemoteComponent
    Microsoft.VisualStudio.Tools.Office.RemoteBindableComponent
      Microsoft.Office.Tools.Excel.Chart
      Microsoft.Office.Tools.Excel.ListObject
      Microsoft.Office.Tools.Excel.NamedRange
      Microsoft.Office.Tools.Excel.XmlMappedRange
      Microsoft.Office.Tools.Word.Bookmark
      Microsoft.Office.Tools.Word.ContentControlBase
      Microsoft.Office.Tools.Word.XMLNode

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Siehe auch

Referenz

RemoteBindableComponent-Member

Microsoft.VisualStudio.Tools.Office-Namespace

Weitere Ressourcen

Übersicht über Hostelemente und Hoststeuerelemente