RemoteBindableComponent.DataBindings 属性 (2007 system)
更新: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 绑定到 NamedRange 的 Value2 属性。此代码示例摘自一个为 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);
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。