この記事は翻訳者によって翻訳されたものです。 記事の文章にポインターを重ねると、原文のテキストが表示されます。 |
訳文
原文
|
Control.BindingContext プロパティ
コントロールの BindingContext を取得または設定します。
アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)
[BrowsableAttribute(false)] public virtual BindingContext BindingContext { get; set; }
実装
IBindableComponent.BindingContextControl の BindingContext を使用して、Control に含まれるすべてのデータ バインド コントロールの単一の BindingManagerBase を返します。 BindingManagerBase は、同期をとっている同一のデータ ソースにバインドされたすべてのコントロールを維持します。 たとえば、BindingManagerBase の Position プロパティを設定して、すべてのデータ連結コントロールが指している、基になるリストの項目を指定します。
新しい BindingContext の作成方法とそれを BindingContext プロパティに割り当てる方法の詳細については、BindingContext のトピックを参照してください。
継承時の注意
派生クラスで BindingContext プロパティをオーバーライドする場合は、基本クラスの BindingContext プロパティを使用して、基本の実装を拡張します。 それ以外の場合は、すべての実装を提供する必要があります。 BindingContext プロパティの get アクセサーと set アクセサーの両方をオーバーライドする必要はありません。必要に応じて 1 つのアクセサーだけをオーバーライドできます。
4 つの Binding オブジェクトを作成して、5 つのコントロール (1 つの DateTimePicker コントロールと 4 つの TextBox コントロール) を複数のデータ ソースにバインドするコード例を次に示します。 さらに、BindingContext を使用して、各データ ソースの BindingManagerBase を取得します。
protected void BindControls() { /* Create two Binding objects for the first two TextBox controls. The data-bound property for both controls is the Text property. The data source is a DataSet (ds). The data member is a navigation path in the form: "TableName.ColumnName". */ text1.DataBindings.Add(new Binding ("Text", ds, "customers.custName")); text2.DataBindings.Add(new Binding ("Text", ds, "customers.custID")); /* Bind the DateTimePicker control by adding a new Binding. The data member of the DateTimePicker is a navigation path: TableName.RelationName.ColumnName string. */ DateTimePicker1.DataBindings.Add(new Binding("Value", ds, "customers.CustToOrders.OrderDate")); /* Add event delegates for the Parse and Format events to a new Binding object, and add the object to the third TextBox control's BindingsCollection. The delegates must be added before adding the Binding to the collection; otherwise, no formatting occurs until the Current object of the BindingManagerBase for the data source changes. */ Binding b = new Binding ("Text", ds, "customers.custToOrders.OrderAmount"); b.Parse+=new ConvertEventHandler(CurrencyStringToDecimal); b.Format+=new ConvertEventHandler(DecimalToCurrencyString); text3.DataBindings.Add(b); // Get the BindingManagerBase for the Customers table. bmCustomers = this.BindingContext [ds, "Customers"]; /* Get the BindingManagerBase for the Orders table using the RelationName. */ bmOrders = this.BindingContext[ds, "customers.CustToOrders"]; /* Bind the fourth TextBox control's Text property to the third control's Text property. */ text4.DataBindings.Add("Text", text3, "Text"); }
Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2
.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。