BindingSource.ResetBindings(Boolean) メソッド

定義

BindingSourceにバインドされたコントロールがリスト内のすべての項目を再読み込みし、表示される値を更新します。

public:
 void ResetBindings(bool metadataChanged);
public void ResetBindings(bool metadataChanged);
member this.ResetBindings : bool -> unit
Public Sub ResetBindings (metadataChanged As Boolean)

パラメーター

metadataChanged
Boolean

true データ スキーマが変更された場合。値のみが変更された場合に false します。

次のコード例では、 BindingSource コンポーネントを使用して、変更通知を提供しない配列リストをバインドします。 項目がリストから削除され、バインドされたコントロールには、 ResetBindings メソッドを呼び出すことによって変更が通知されます。 このコード例は、How to: Reflect Data Source Updates in a Windows フォーム Control with the BindingSource で提供されるより大きな例の一部です。

private:
   void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      String^ xml = "<US><states>"
         + "<state><name>Washington</name><capital>Olympia</capital> "
         + "<flower>Coast Rhododendron</flower></state>"
         + "<state><name>Oregon</name><capital>Salem</capital>"
         + "<flower>Oregon Grape</flower></state>"
         + "<state><name>California</name><capital>Sacramento</capital>"
         + "<flower>California Poppy</flower></state>"
         + "<state><name>Nevada</name><capital>Carson City</capital>"
         + "<flower>Sagebrush</flower></state>"
         + "</states></US>";
      
      // Convert the xml string to bytes and load into a memory stream.
      array<Byte>^ xmlBytes = Encoding::UTF8->GetBytes( xml );
      MemoryStream^ stream = gcnew MemoryStream( xmlBytes,false );
      
      // Create a DataSet and load the xml into it.
      dataSet2->ReadXml( stream );
      
      // Set the data source.
      bindingSource1->DataSource = dataSet2;
      bindingSource1->ResetBindings( true );
   }
private void button1_Click(object sender, EventArgs e)
{
    // If items remain in the list, remove the first item. 
    if (states.Count > 0)
    {
        states.RemoveAt(0);

        // Call ResetBindings to update the textboxes.
        bindingSource1.ResetBindings(false);
    }
}

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
    Handles button1.Click

    ' If items remain in the list, remove the first item. 
    If states.Count > 0 Then
        states.RemoveAt(0)

        ' Call ResetBindings to update the textboxes.
        bindingSource1.ResetBindings(False)
    End If

End Sub

注釈

ResetBindings メソッドは、BindingSourceにバインドされているすべてのコントロールに値を更新するように通知します。 このメソッドは、 ListChanged イベントを少なくとも 1 回発生させることでこれを行います。 metaDataChanged パラメーターは、基になる変更の性質を示します。

metaDataChangedの値に関係なく、ListChangedEventArgs.ListChangedTypeListChangedType.Reset に設定されたListChanged イベントが発生します。 その結果、trueのパラメーターを指定してResetBindingsを呼び出すと、2 つのListChanged イベントが発生します。

ResetBindings は、 DataSource プロパティや DataMember プロパティの設定など、別のメンバーがデータ バインディングに大きな変更を加えるたびに自動的に呼び出されます。 ただし、プログラマはこのメソッドを明示的に呼び出すこともできます。

適用対象

こちらもご覧ください