BindingSource.ResetItem(Int32) Metod

Definition

Orsakar en kontroll som är bunden till BindingSource för att läsa om objektet vid det angivna indexet och uppdatera dess visade värde.

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

Parametrar

itemIndex
Int32

Det nollbaserade indexet för objektet som har ändrats.

Exempel

I följande kodexempel används en BindingSource komponent för att binda en lista till en DataGridView kontroll. Listan genererar inte ändringsmeddelanden, så ResetItem metoden på BindingSource används för att skapa ListChanged händelsen. Det här kodexemplet är en del av ett större exempel i How to: Raise Change Notifications Using the BindingSource ResetItem Method (Skapa ändringsmeddelanden med metoden 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

Kommentarer

Metoden ResetItem meddelar alla kontroller som är bundna till objektet vid den angivna Position för att uppdatera deras värden. Metoden gör detta genom att höja ListChanged händelsen med ListChangedEventArgs.ListChangedType inställt på ListChangedType.ItemChanged.

ResetItem anropas automatiskt när ändringar görs i värdet för ett enskilt objekt. Programmeraren kan dock också uttryckligen kalla den här metoden.

Gäller för

Se även