BindingSource.ResetItem(Int32) 方法

定義

使得繫結至 BindingSource 的控制項重新讀取指定索引上的項目,並重新整理其顯示的值。

public:
 void ResetItem(int itemIndex);
public void ResetItem (int itemIndex);
member this.ResetItem : int -> unit
Public Sub ResetItem (itemIndex As Integer)

參數

itemIndex
Int32

已變更的項目之以零為起始的索引。

範例

下列程式碼範例會使用 BindingSource 元件將清單系結至 DataGridView 控制項。 清單不會引發變更通知,因此 會 ResetItem 使用 上的 BindingSource 方法來引發 ListChanged 事件。 此程式碼範例是 如何:使用 BindingSource ResetItem 方法引發變更通知中提供之較大範例的一部分。

// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Get a reference to the list from the BindingSource.
   List< DemoCustomer^ >^ customerList =
      static_cast<List< DemoCustomer^ >^>(
        this->customersBindingSource->DataSource);
   
   // Change the value of the CompanyName property for the
   // first item in the list.
   customerList->default[ 0 ]->CompanyName = L"Tailspin Toys";
   
   // Call ResetItem to alert the BindingSource that the
   // list has changed.
   this->customersBindingSource->ResetItem( 0 );
}
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click(object sender, EventArgs e)
{
    // Get a reference to the list from the BindingSource.
    List<DemoCustomer> customerList = 
        this.customersBindingSource.DataSource as List<DemoCustomer>;

    // Change the value of the CompanyName property for the 
    // first item in the list.
    customerList[0].CompanyName = "Tailspin Toys";

    // Call ResetItem to alert the BindingSource that the 
    // list has changed.
    this.customersBindingSource.ResetItem(0);
}
' This event handler changes the value of the CompanyName
' property for the first item in the list.
Private Sub changeItemBtn_Click(ByVal sender As Object, ByVal e As EventArgs) _
   Handles changeItemBtn.Click

    ' Get a reference to the list from the BindingSource.
    Dim customerList As List(Of DemoCustomer) = _
    CType(Me.customersBindingSource.DataSource, List(Of DemoCustomer))

    ' Change the value of the CompanyName property for the 
    ' first item in the list.
    customerList(0).CompanyName = "Tailspin Toys"

    ' Call ResetItem to alert the BindingSource that the 
    ' list has changed.
    Me.customersBindingSource.ResetItem(0)

End Sub

備註

方法 ResetItem 會通知系結至指定 Position 之 專案的所有控制項,以重新整理其值。 方法會藉由引發 ListChanged 設定為 ListChangedType.ItemChanged 的事件 ListChangedEventArgs.ListChangedType 來執行此動作。

ResetItem 每當對個別專案的值進行變更時,就會自動呼叫 。 不過,程式設計人員也可以明確呼叫這個方法。

適用於

另請參閱