BindingSource.ResetItem(Int32) Methode

Definition

Führt dazu, dass in ein an BindingSource gebundenes Steuerelement das Element am angegebenen Index erneut eingelesen und sein angezeigter Wert aktualisiert wird.Causes a control bound to the BindingSource to reread the item at the specified index, and refresh its displayed value.

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

Parameter

itemIndex
Int32

Der nullbasierte Index des geänderten Elements.The zero-based index of the item that has changed.

Beispiele

Im folgenden Codebeispiel wird eine BindingSource Komponente verwendet, um eine Liste an ein DataGridView Steuerelement zu binden.The following code example uses a BindingSource component to bind a list to a DataGridView control. Die Liste gibt keine Änderungs Benachrichtigungen aus, sodass die ResetItem-Methode für die BindingSource verwendet wird, um das ListChanged Ereignis zu erhöhen.The list does not raise change notifications, so the ResetItem method on the BindingSource is used to raise the ListChanged event. Dieses Codebeispiel ist Teil eines größeren Beispiels, das in Gewusst wie: Aufrufen von Änderungs Benachrichtigungen mithilfe der BindingSource ResetItem-Methodebereitgestellt wird.This code example is part of a larger example provided in How to: Raise Change Notifications Using the BindingSource ResetItem Method.

// 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

Hinweise

Die ResetItem-Methode benachrichtigt alle Steuerelemente, die an das Element an der angegebenen Position gebunden sind, um ihre Werte zu aktualisieren.The ResetItem method notifies all controls bound to the item at the specified Position to refresh their values. Die-Methode bewirkt dies, indem das ListChanged-Ereignis mit ListChangedEventArgs.ListChangedType auf ListChangedType.ItemChangedfestgelegt wird.The method does this by raising the ListChanged event with ListChangedEventArgs.ListChangedType set to ListChangedType.ItemChanged.

ResetItem wird automatisch aufgerufen, wenn Änderungen an dem Wert eines einzelnen Elements vorgenommen werden.ResetItem is automatically called whenever changes are made to the value of an individual item. Der Programmierer kann diese Methode jedoch auch explizit aufzurufen.However, the programmer can also call this method explicitly.

Gilt für:

Siehe auch