ControlBindingsCollection.Item[String] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由控件的属性名指定的 Binding。
public:
property System::Windows::Forms::Binding ^ default[System::String ^] { System::Windows::Forms::Binding ^ get(System::String ^ propertyName); };
public System.Windows.Forms.Binding this[string propertyName] { get; }
member this.Item(string) : System.Windows.Forms.Binding
Default Public ReadOnly Property Item(propertyName As String) As Binding
参数
- propertyName
- String
该数据绑定控件的属性的名称。
属性值
将指定的控件属性绑定到数据源的 Binding。
示例
下面的代码示例从一个值返回一 Binding 个 ControlBindingsCollection。
void PrintValue()
{
ControlBindingsCollection^ myControlBindings;
myControlBindings = textBox1->DataBindings;
// Get the Binding for the Text property.
Binding^ myBinding = myControlBindings[ "Text" ];
// Assuming the data source is a DataTable.
DataRowView^ drv;
drv = dynamic_cast<DataRowView^>(myBinding->BindingManagerBase->Current);
// Assuming a column named S"custName" exists, print the value.
Console::WriteLine( drv[ "custName" ] );
}
private void PrintValue()
{
ControlBindingsCollection myControlBindings;
myControlBindings = textBox1.DataBindings;
// Get the Binding for the Text property.
Binding myBinding = myControlBindings["Text"];
// Assuming the data source is a DataTable.
DataRowView drv;
drv = (DataRowView) myBinding.BindingManagerBase.Current;
// Assuming a column named "custName" exists, print the value.
Console.WriteLine(drv["custName"]);
}
Private Sub PrintValue()
Dim myControlBindings As ControlBindingsCollection = _
textBox1.DataBindings
' Get the Binding for the Text property.
Dim myBinding As Binding = myControlBindings("Text")
' Assuming the data source is a DataTable.
Dim drv As DataRowView = _
CType( myBinding.BindingManagerBase.Current, DataRowView)
' Assuming a column named "custName" exists, print the value.
Console.WriteLine(drv("custName"))
End Sub
注解
如果指定的属性与集合中的绑定不匹配, Item[] 则 null
返回 。