BindingManagerBase クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


BindingManagerBase は、同じデータ ソースにバインドされた Windows フォームのデータ バインド コントロールを同期できるようにします。データ ソースへのコントロールの単純バインディングの詳細については、Binding クラスのトピックを参照してください。たとえば、同じデータ ソースの異なる列にバインドされた 2 つの TextBox コントロールが配置されているフォームがあるとします。データ ソースは顧客の名前を格納している DataTable であり、列には姓と名が格納されているとします。同じ顧客に対して正しい姓と名を同時に表示するには、この 2 つのコントロールを同期させます。BindingManagerBase クラスから継承された CurrencyManager が、データ ソースの現在の項目へのポインタを維持することで、この同期を実行します。TextBox コントロールは、現在の項目にバインドされているため、同じ行の情報を表示します。現在の項目が変更されると、CurrencyManager が、すべての連結コントロールにデータを更新するように通知します。さらに、Position プロパティを設定して、コントロールが指す DataTable の行を指定できます。データ ソース内の行の数を確認するには、Count プロパティを使用します。
データ ソースが現在の項目のポインタを維持しているとは限らないため、CurrencyManager が必要です。たとえば、配列と ArrayList オブジェクトはデータ ソースになる場合がありますが、現在の項目を返すプロパティは持っていません。現在の項目を取得するには、Current プロパティを使用します。
PropertyManager も BindingManagerBase から継承され、データ ソース内の現在のオブジェクトのプロパティではなく、オブジェクトの現在のプロパティを維持するために使用されます。このため、PropertyManager に対する Position プロパティまたは Count プロパティの設定は無効です。
BindingManagerBase を作成するには、BindingContext クラスを使用します。この操作では、管理されているデータ ソースに応じて、CurrencyManager または PropertyManager のいずれかが返されます。
ソリューション プログラマは、コントロールを BindingSource コンポーネントに直接バインドすることをお勧めします。これは、データ ソースと、実際の対象データ ソースへのデータ コネクタの両方として機能します。BindingSource により、コントロールと対象の間の現在性の管理など、単純または複合データ バインディングが大幅に簡素化されます。
継承時の注意 BindingManagerBase から継承する場合は、抽象メンバである AddNew、Count、CancelCurrentEdit、Current、EndCurrentEdit、GetItemProperties、OnCurrentChanged、Position、RemoveAt、ResumeBinding、SuspendBinding、および UpdateIsBinding をオーバーライドする必要があります。
BindingContext を使用して、特定のデータ ソースに対して BindingManagerBase を返すコード例を次に示します。この例では、モジュールの宣言セクションで myBindingManagerBase を宣言していることを前提にしています。さらに、この例では CurrentChanged イベントおよび PositionChanged イベントにイベント デリゲートを追加しています。最後に、この例には、Position プロパティをインクリメントまたはデクリメントし、Position をリストの最初または最後の行に設定する 4 つのメソッド (MoveNext、MovePrevious、MoveFirst、および MoveLast) が含まれています。リストの最後の行は、Count プロパティを使用して確認します。
Private Sub GetBindingManagerBase ' CustomersToOrders is the RelationName of a DataRelation. ' Therefore, the list maintained by the BindingManagerBase is the ' list of orders that belong to a specific customer in the ' DataTable named Customers, found in DataSet. myBindingManagerBase = Me.BindingContext(DataSet1, _ "Customers.CustomersToOrders") ' Adds delegates to the CurrentChanged and PositionChanged events. AddHandler myBindingManagerBase.PositionChanged, _ AddressOf BindingManagerBase_PositionChanged AddHandler myBindingManagerBase.CurrentChanged, _ AddressOf BindingManagerBase_CurrentChanged End Sub Private Sub BindingManagerBase_PositionChanged _ (sender As Object, e As EventArgs) ' Prints the new Position of the BindingManagerBase. Console.Write("Position Changed: ") Console.WriteLine(CType(sender, BindingManagerBase).Position) End Sub Private Sub BindingManagerBase_CurrentChanged _ (sender As Object, e As EventArgs) ' Prints the new value of the current object. Console.Write("Current Changed: ") Console.WriteLine(CType(sender, BindingManagerBase).Current) End Sub Private Sub MoveNext ' Increments the Position property value by one. myBindingManagerBase.Position += 1 End Sub Private Sub MovePrevious ' Decrements the Position property value by one. myBindingManagerBase.Position -= 1 End Sub Private Sub MoveFirst ' Goes to the first row in the list. myBindingManagerBase.Position = 0 End Sub Private Sub MoveLast ' Goes to the last row in the list. myBindingManagerBase.Position = _ myBindingManagerBase.Count - 1 End Sub
private void GetBindingManagerBase() { /* CustomersToOrders is the RelationName of a DataRelation. Therefore, the list maintained by the BindingManagerBase is the list of orders that belong to a specific customer in the DataTable named Customers, found in DataSet1. */ myBindingManagerBase = this.BindingContext[DataSet1, "Customers.CustomersToOrders"]; // Adds delegates to the CurrentChanged and PositionChanged events. myBindingManagerBase.PositionChanged += new EventHandler(BindingManagerBase_PositionChanged); myBindingManagerBase.CurrentChanged += new EventHandler(BindingManagerBase_CurrentChanged); } private void BindingManagerBase_PositionChanged (object sender, EventArgs e) { // Prints the new Position of the BindingManagerBase. Console.Write("Position Changed: "); Console.WriteLine(((BindingManagerBase)sender).Position); } private void BindingManagerBase_CurrentChanged (object sender, EventArgs e) { // Prints the new value of the current object. Console.Write("Current Changed: "); Console.WriteLine(((BindingManagerBase)sender).Current); } private void MoveNext() { // Increments the Position property value by one. myBindingManagerBase.Position += 1; } private void MovePrevious() { // Decrements the Position property value by one. myBindingManagerBase.Position -= 1; } private void MoveFirst() { // Goes to the first row in the list. myBindingManagerBase.Position = 0; } private void MoveLast() { // Goes to the last row in the list. myBindingManagerBase.Position = myBindingManagerBase.Count - 1; }
void GetBindingManagerBase() { /* CustomersToOrders is the RelationName of a DataRelation. Therefore, the list maintained by the BindingManagerBase is the list of orders that belong to a specific customer in the DataTable named Customers, found in DataSet1. */ myBindingManagerBase = this->BindingContext[DataSet1, "Customers.CustomersToOrders"]; // Adds delegates to the CurrentChanged and PositionChanged events. myBindingManagerBase->PositionChanged += gcnew EventHandler( this, &Form1::BindingManagerBase_PositionChanged ); myBindingManagerBase->CurrentChanged += gcnew EventHandler( this, &Form1::BindingManagerBase_CurrentChanged ); } void BindingManagerBase_PositionChanged( Object^ sender, EventArgs^ /*e*/ ) { // Prints the new Position of the BindingManagerBase. Console::Write( "Position Changed: " ); Console::WriteLine( (dynamic_cast<BindingManagerBase^>(sender))->Position ); } void BindingManagerBase_CurrentChanged( Object^ sender, EventArgs^ /*e*/ ) { // Prints the new value of the current object. Console::Write( "Current Changed: " ); Console::WriteLine( (dynamic_cast<BindingManagerBase^>(sender))->Current ); } void MoveNext() { // Increments the Position property value by one. myBindingManagerBase->Position = myBindingManagerBase->Position + 1; } void MovePrevious() { // Decrements the Position property value by one. myBindingManagerBase->Position = myBindingManagerBase->Position - 1; } void MoveFirst() { // Goes to the first row in the list. myBindingManagerBase->Position = 0; } void MoveLast() { // Goes to the last row in the list. myBindingManagerBase->Position = myBindingManagerBase->Count - 1; }
private void GetBindingManagerBase() { /* CustomersToOrders is the RelationName of a DataRelation. Therefore, the list maintained by the BindingManagerBase is the list of orders that belong to a specific customer in the DataTable named Customers, found in dataSet1. */ myBindingManagerBase = this.get_BindingContext().get_Item(dataSet1, "Customers.CustomersToOrders"); // Adds delegates to the CurrentChanged and PositionChanged events. myBindingManagerBase.add_PositionChanged(new EventHandler (BindingManagerBase_PositionChanged)); myBindingManagerBase.add_CurrentChanged(new EventHandler (BindingManagerBase_CurrentChanged)); } //GetBindingManagerBase private void BindingManagerBase_PositionChanged(Object sender, EventArgs e) { // Prints the new Position of the BindingManagerBase. Console.Write("Position Changed: "); Console.WriteLine(((BindingManagerBase)(sender)).get_Position()); } //BindingManagerBase_PositionChanged private void BindingManagerBase_CurrentChanged(Object sender, EventArgs e) { // Prints the new value of the current object. Console.Write("Current Changed: "); Console.WriteLine(((BindingManagerBase)(sender)).get_Current()); } //BindingManagerBase_CurrentChanged private void MoveNext() { // Increments the Position property value by one. myBindingManagerBase.set_Position(myBindingManagerBase.get_Position() + 1); } //MoveNext private void MovePrevious() { // Decrements the Position property value by one. myBindingManagerBase.set_Position(myBindingManagerBase.get_Position() - 1); } //MovePrevious private void MoveFirst() { // Goes to the first row in the list. myBindingManagerBase.set_Position(0); } //MoveFirst private void MoveLast() { // Goes to the last row in the list. myBindingManagerBase.set_Position(myBindingManagerBase.get_Count() - 1); } //MoveLast

System.Windows.Forms.BindingManagerBase
System.Windows.Forms.CurrencyManager
System.Windows.Forms.PropertyManager


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BindingManagerBase メンバ
System.Windows.Forms 名前空間
BindingSource
BindingContext クラス
CurrencyManager
PropertyManager
Weblioに収録されているすべての辞書からBindingManagerBase クラスを検索する場合は、下記のリンクをクリックしてください。

- BindingManagerBase クラスのページへのリンク