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 更新 in a Windows Forms 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 事件一次來執行此動作; metaDataChanged 參數表示基礎變更的本質。

不論 的值 metaDataChanged 為何, ListChanged 事件都會以 設定為 ListChangedType.Reset 引發 ListChangedEventArgs.ListChangedType 。 因此,使用 的參數 true 呼叫 ResetBindings 將會引發兩 ListChanged 個事件。

ResetBindings 每當另一個成員對資料系結進行重大變更時,就會自動呼叫 ,例如設定 DataSourceDataMember 屬性。 不過,程式設計人員也可以明確呼叫這個方法。

適用於

另請參閱