コントロールのプロパティ名で指定した Binding を取得します。
[C#] C# では、このプロパティは ControlBindingsCollection クラスのインデクサになります。
Overloads Public Default ReadOnly Property Item( _
ByVal propertyName As String _) As Binding
[C#]
public Binding this[stringpropertyName] {get;}
[C++]
public: __property Binding* get_Item(String* propertyName);
[JScript]
returnValue = ControlBindingsCollectionObject.Item(propertyName);またはreturnValue = ControlBindingsCollectionObject(propertyName);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- propertyName
データ連結コントロールのプロパティの名前。
パラメータ [Visual Basic, C#, C++]
- propertyName
データ連結コントロールのプロパティの名前。
プロパティ値
指定したコントロール プロパティをデータ ソースにバインドする Binding 。
解説
ControlBindingsCollection から単一の Binding を返す例を次に示します。
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
[C#]
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"]);
}
[C++]
private:
void PrintValue() {
ControlBindingsCollection* myControlBindings;
myControlBindings = textBox1->DataBindings;
// Get the Binding for the Text property.
Binding* myBinding = myControlBindings->Item[S"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->Item[S"custName"]);
}
使用例
Item プロパティを使用して、 TextBox コントロールの Text プロパティに Binding を返す例を次に示します。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
ControlBindingsCollection クラス | ControlBindingsCollection メンバ | System.Windows.Forms 名前空間 | ControlBindingsCollection.Item オーバーロードの一覧